标签:ima http clu strong lan inf double int ble
设 f[i] 表示状态为 i 时的最大概率
那么很明显,f的转移为
但是如果我们这样做就要枚举i,j,k,时间会炸
所以要找优化的方法
认真观察,会发现其实k可以与处理出来
设两个数组,cnt[i],log[i]
log[i]表示i是2的几次方(向下取整)
cnt[i]状态为i时的k
log的转移
cnt的转移
那么f的转移可以改为
#include<cstdio> #include<iostream> #include<cstring> using namespace std; double f[2097151]; int a[30][30],log[2097151],n,cnt[2097151]; int main() { scanf("%d",&n); for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) scanf("%d",&a[i][j]); log[0]=-1; for (int i=1;i<(1<<n);i++) log[i]=log[i/2]+1; cnt[0]=0; for (int i=1;i<(1<<n);i++) cnt[i]=cnt[i-(1<<log[i])]+1; f[0]=1; for (int i=0;i<(1<<n);i++) for (int j=1;j<=n;j++) if((i&(1<<(j-1)))==0) f[i|(1<<j-1)]=max(f[i|(1<<j-1)],f[i]*a[j][cnt[i]+1]*1.0/100); printf("%.6lf\n",f[(1<<n)-1]*100); }
标签:ima http clu strong lan inf double int ble
原文地址:https://www.cnblogs.com/nibabadeboke/p/11332833.html