poj 3211 01 背包
2011-11-17 05:17
239 查看
#include<stdio.h> #include<string.h> int m,n; char str[15][15]; int col[110][22]; bool dp[200000]; int t[110],s[110],g[110][110]; int getid(char *s) { for(int i=0;i<m;i++) if(strcmp(s,str[i])==0) return i; return 0; } int main() { int i,j,k; char tmp[15]; while(scanf("%d%d",&m,&n)!=EOF) { if(n==0&&m==0) break; for(i=0;i<m;i++)scanf("%s",str[i]),t[i]=s[i]=0; for(i=0;i<n;i++) { scanf("%d%s",&k,tmp); s[j=getid(tmp)]+=k; g[j][t[j]++]=k; } int ans; for(ans=k=0;k<m;k++) { for(i=0;i<=s[k]/2;i++) dp[i]=0; dp[0]=1; for(i=0;i<t[k];i++) for(j=s[k]/2;j>=g[k][i];j--) if(dp[j-g[k][i]]) dp[j]=1; for(i=s[k]/2;i>=0;i--) if(dp[i]) break; ans+=s[k]-i; } printf("%d\n",ans); } return 0; }
相关文章推荐
- POJ 3211 —— Washing Clothes 01背包
- POJ 3211 Washing Clothes(01背包变型)
- POJ 3211 Washing Cloths(01背包变形)
- poj-3211-01背包
- 01分组背包-poj 3211 Washing Clothes
- 【POJ1014】Dividing 多重背包,二进制物品拆分转01背包
- poj 2151 01背包
- POJ 2184 Cow Exhibition (01背包变形)(或者搜索)
- POJ 3624 Charm Bracelet (01)(背包入门)
- poj 2923 状态压缩 + 01背包
- POJ 1155 TELE 树形01背包,有tric...
- POJ-2184-01背包变形-Cow Exhibition
- poj 3211 Washing Clothes 背包
- poj 1948 二维01背包
- poj 3624 Charm Bracelet(01背包入门题)
- POJ 3628 Bookshelf 2(DP:01背包)
- POJ - 2923 (01背包,状态压缩)
- http://poj.org/problem?id=1948..二维01背包。。
- poj 1014 -- 01背包 完全背包 多重背包 代码详解
- poj 3211 Washing Clothes(背包)