标签:des style blog http color io os ar java
3 4 3 2 2 3 2 1 3 2 1 2 3 2 3 1 3 2 2 3 2 3 1 3 1 2 3 0 0 0
3 -3
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <climits> 7 #include <vector> 8 #include <queue> 9 #include <cstdlib> 10 #include <string> 11 #include <set> 12 #include <stack> 13 #define LL long long 14 #define pii pair<int,int> 15 #define INF 0x3f3f3f3f 16 using namespace std; 17 const int maxn = 22; 18 int G,B,S,bag[maxn][maxn],dp[1<<maxn]; 19 int dfs(int cur,int sum,int *cooker){ 20 if(cur == 0 || sum <= 0) return 0; 21 if(dp[cur]) return dp[cur]; 22 int ans = 0; 23 for(int i = 0; i < B; ++i){ 24 if(cur&(1<<i)){ 25 int sta = cur^(1<<i),ret = 0,tcooker[maxn] = {0}; 26 for(int k = 0; k < maxn; ++k){ 27 tcooker[k] += cooker[k] + bag[i][k]; 28 ret += tcooker[k]/S; 29 tcooker[k] %= S; 30 } 31 if(ret) ans = max(ans,ret+dfs(sta,sum-ret,tcooker)); 32 else ans = max(ans,sum - dfs(sta,sum,tcooker)); 33 } 34 } 35 return dp[cur] = ans; 36 } 37 int main() { 38 while(scanf("%d %d %d",&G,&B,&S),G||B||S){ 39 int n,tmp,sum; 40 int cooker[maxn] = {0}; 41 memset(bag,0,sizeof(bag)); 42 for(int i = 0; i < B; ++i){ 43 scanf("%d",&n); 44 while(n--){ 45 scanf("%d",&tmp); 46 ++bag[i][tmp]; 47 cooker[tmp]++; 48 } 49 } 50 for(int i = sum = 0; i < maxn; ++i) sum += cooker[i]/S; 51 memset(dp,0,sizeof(dp)); 52 memset(cooker,0,sizeof(cooker)); 53 printf("%d\n",2*dfs((1<<B)-1,sum,cooker) - sum); 54 } 55 return 0; 56 }
标签:des style blog http color io os ar java
原文地址:http://www.cnblogs.com/crackpotisback/p/4049756.html