标签:blog io ar os for sp 2014 log 代码
题意:代码:
#include"cstdlib" #include"cstdio" #include"cstring" #include"cmath" #include"queue" #include"algorithm" #include"iostream" #define inf 99999999 using namespace std; int bag[22][12],c[12]; int dp[1<<22]; int g,n,s; int dfs(int x,int sum,int used[]) { if(x==0||sum==0) return 0; if(dp[x]!=inf) return dp[x]; int ans=0,mark[12]; memset(mark,0,sizeof(mark)); for(int i=0; i<n; i++) { int pp=0; if(x&(1<<i)) { int tep=x^(1<<i),cnt=0; for(int j=0; j<g; j++) { mark[j]=used[j]+bag[i][j]; cnt+=mark[j]/s; mark[j]%=s; } if(cnt>0) pp=cnt+dfs(tep,sum-cnt,mark); //构成魔法石继续取 else pp=sum-dfs(tep,sum,mark); //换人了 得到的就是别人剩下的 ans=max(ans,pp); } } return dp[x]=ans; } int main() { while(scanf("%d%d%d",&g,&n,&s),(g+n+s)) { memset(bag,0,sizeof(bag)); memset(c,0,sizeof(c)); for(int i=0; i<n; i++) { int x; scanf("%d",&x); while(x--) { int y; scanf("%d",&y); bag[i][y-1]++; c[y-1]++; } } int sum=0; for(int i=0; i<g; i++) sum+=c[i]/s; //统计能构成多少个魔法石 for(int i=0; i<(1<<n); i++) dp[i]=inf; int used[12]; memset(used,0,sizeof(used)); int ans=dfs((1<<n)-1,sum,used); printf("%d\n",ans-(sum-ans)); } return 0; }
标签:blog io ar os for sp 2014 log 代码
原文地址:http://blog.csdn.net/wdcjdtc/article/details/40820089