JZOJ 1236. 邦德I
题目
分析
- 状压设f[s]为前i个人的情况为s
代码
1 #include<iostream> 2 #include<cstdio> 3 using namespace std; 4 double f[1<<21]; 5 double a[100][100]; 6 int main () 7 { 8 int n; 9 cin>>n; 10 for (int i=1;i<=n;i++) 11 for (int j=1;j<=n;j++) 12 cin>>a[i][j],a[i][j]/=100; 13 int maxn=(1<<n)-1; 14 f[0]=1; 15 for (int i=0;i<=maxn;i++) 16 { 17 int x=__builtin_popcount(i); 18 for (int j=1;j<=n;j++) 19 { 20 if (x==j-1) 21 { 22 for (int k=1;k<=n;k++) 23 if (!(i&(1<<(k-1)))) 24 { 25 f[i|(1<<(k-1))]=max(f[i|(1<<(k-1))],f[i]*a[j][k]); 26 } 27 } 28 } 29 } 30 printf("%0.6lf",f[maxn]*100); 31 }
为何要逼自己长大,去闯不该闯的荒唐