标签:line continue cst mes main math scan names ring
状压DP
\(dp[i]\)表示当前选人状态为\(i\)且选择了前\(i.count()\)个物品时最大的概率
#include"cstdio"
#include"cstring"
#include"iostream"
#include"algorithm"
using namespace std;
const int MAXN=20;
int n;
double f[MAXN+1][MAXN+1];
double dp[1<<MAXN];
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;++i){
for(int j=1;j<=n;++j){
scanf("%lf",&f[i][j]);
}
}dp[0]=100;
for(int i=0;i<1<<n;++i){
int nw=i,ct=0;
while(nw) nw&=nw-1,++ct;
for(int j=1;j<=n;++j){
if(i&(1<<j-1)) continue;
dp[i|(1<<j-1)]=max(dp[i|(1<<j-1)],dp[i]*f[j][ct+1]/100);
}
}printf("%.10lf\n",dp[(1<<n)-1]);
return 0;
}
标签:line continue cst mes main math scan names ring
原文地址:https://www.cnblogs.com/AH2002/p/10063619.html