标签:des style blog http color io os java ar
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 327680/327680 K (Java/Others)
Total Submission(s): 1069 Accepted Submission(s): 456
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #include <vector> 5 #include <iostream> 6 using namespace std; 7 #define INF 0xffffff 8 struct abcd 9 { 10 int a[10]; 11 }p[30]; 12 int g,b,s,x; 13 int dp[1<<22],bb[10]; 14 int main() 15 { 16 // freopen("in.txt","r",stdin); 17 int i,j,k,cnt,m; 18 while(scanf("%d%d%d",&g,&b,&s),(g|b|s)) 19 { 20 memset(p,0,sizeof(p)); 21 for(i=0;i<b;i++) 22 { 23 scanf("%d",&m); 24 for(j=0;j<m;j++) 25 { 26 scanf("%d",&x); 27 p[i].a[x]++; 28 } 29 } 30 for(i=0;i<(1<<b);i++) 31 dp[i]=-INF; 32 dp[0]=0; 33 for(i=1;i<(1<<b);i++) 34 { 35 memset(bb,0,sizeof(bb)); 36 for(j=0;j<b;j++) 37 { 38 if(!(i&(1<<j))) 39 { 40 for(k=1;k<=g;k++) 41 bb[k]+=p[j].a[k]; 42 } 43 } 44 for(j=1;j<=g;j++)bb[j]%=s; 45 for(j=0;j<b;j++) 46 { 47 if((i&(1<<j))) 48 { 49 cnt=0; 50 for(k=1;k<=g;k++) 51 { 52 cnt+=(bb[k]+p[j].a[k])/s; 53 } 54 if(cnt) 55 dp[i]=max(dp[i],dp[i^(1<<j)]+cnt); 56 else dp[i]=max(dp[i],-dp[i^(1<<j)]); 57 } 58 } 59 } 60 printf("%d\n",dp[(1<<b)-1]); 61 } 62 63 }
标签:des style blog http color io os java ar
原文地址:http://www.cnblogs.com/ERKE/p/3982055.html