scoi 2008 && bzoj 1076 奖励关

时间:2022-10-23 06:56:34

传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=3223

思路:15?好,状压,OK.

这是转移方程

if((s[k]&j)==s[k])

f[i][j]+=max(f[i+1][j],f[i+1][j|1<<(k-1)]+a[k]);

else f[i][j]+=f[i+1][j];

代码

#include <cstdio>
#include <cmath>
#include <iostream>
#include <cstring>
#include <algorithm>
#define ll long long
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
int k,n,a[105],s[105];
double f[70000][20];
int main()
{
scanf("%d%d",&k,&n);
for (int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
int x=0;
while (~scanf("%d",&x))
{
if (x==0) break;
s[i]|=1<<(x-1);
}
}
for (int i=k;i>=1;i--)
{
for (int j=0;j<1<<(n);j++)
{
f[i][j]=0.0;
for(int k=1;k<=n;k++)
if((s[k]&j)==s[k])
f[i][j]+=max(f[i+1][j],f[i+1][j|1<<(k-1)]+a[k]);
else f[i][j]+=f[i+1][j];
f[i][j]/=(double)n;
}
}
printf("%lf",f[1][0]);
}