Given G gems, B-Pack. and S. s when the representative of each color of the gem s we can become Philosopher's Stone
Each package contains n gems. Separate c1,c2 ....
Then they took turns to take the bag. Each package can be obtained once. The jewel is out of the bag on the ground.
Suppose you can become a philosopher's Stone with a magic stone, and this person takes the bag again. Did not become the substitution.
The number of magic stones is to get points, ask two people the best time difference is how much.
Compression-like memory search
Altogether 21 packages. State of the current pickup
No matter how it is taken, the number of magic stones that are finally obtained must
Dp[i] is indicated in the I state. The highest score the initiator can get
#include "stdio.h" #include "string.h" int aim,g,b,s;int dp[1<<22],c[25][10];int bit[25];int inf=0x3f3f3f3f;int Max (int a,int b) {if (a<b) return B; else return A;} int dfs (int cur,int sum,int temp[]) {int ans,i,next,j,w,cnt; int mark[10]; if (Cur==aim | | sum==0) return 0; if (Dp[cur]!=inf) return dp[cur]; ans=0; for (i=1;i<=b;i++) if (Cur&bit[i]) {next=cur^bit[i]; cnt=0; for (j=1;j<=g;j++) {mark[j]=temp[j]+c[i][j]; cnt+=mark[j]/s; Mark[j]%=s; } if (cnt>0) W=cnt+dfs (Next,sum-cnt,mark); else W=sum-dfs (Next,sum,mark); Ans=max (ANS,W); } return Dp[cur]=ans;} int main () {int i,n,x,sum,aim,ans; int all[10],mark[25]; Bit[1]=1; for (i=2;i<=22;i++) bit[i]=bit[i-1]*2; while (scanf ("%d%d%d", &g,&b,&s)!=eof) {if (g+b+s==0) break; memset (C,0,sizeof (c)); memset (all,0,sizeof (All)); for (i=1;i<=b;i++) {scanf ("%d", &n); while (n--) {scanf ("%d", &x); c[i][x]++; all[x]++; }} sum=0; for (i=1;i<=g;i++) sum+=all[i]/s; Aim=bit[b+1]-1; memset (Mark,0,sizeof (Mark)); Memset (Dp,inf,sizeof (DP)); Ans=dfs (0,0,mark); printf ("%d\n", ans-(Sum-ans)); } return 0;}
Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.
HDU 4778 Memory Search & pressure