01背包 poj3211 STL助攻
来源:互联网 发布:淘宝入驻条件费用标准 编辑:程序博客网 时间:2024/06/10 18:57
bug一开始头昏脑胀把dp[0]的值赋值为1
#include<stdio.h>#include<algorithm>#include<string.h>#include<vector>#include<cmath>#include<iostream>#include<map>#include<string>using namespace std;typedef long long ll;const ll inf=0x3f3f3f3f;const ll maxn=1010*100;int K,N;int dp[maxn];int main(){ //freopen("D://in.txt","r",stdin); while(scanf("%d%d",&K,&N)!=EOF){ if(K==0&&N==0) break; map<string ,vector<int> >m; m.clear(); for(int i=0;i<K;i++){ string s; cin>>s; m[s].clear(); } for(int i=1;i<=N;i++){ int u; scanf("%d",&u); string s; cin>>s; m[s].push_back(u); } map<string ,vector<int> >::iterator it; int sum=0; for(it=m.begin();it!=m.end();it++){ int n=it->second.size(); if(n==0 ) continue; vector<int> &v=it->second; int W=0; for(int i=0;i<n;i++) W+=v[i]; for(int i=0;i<=n;i++){ for(int j=0;j<=W;j++) dp[j]=0; } dp[0]=0; for(int i=0;i<n;i++){ for(int j=W;j>=v[i];j--){ dp[j]=max(dp[j],dp[j-v[i]]+v[i]); } } //printf("dp %d %d\n",dp[W/2],W-dp[W/2]); sum+=max(dp[W/2],W-dp[W/2]); } printf("%d\n",sum); } return 0;}
0 0
- 01背包 poj3211 STL助攻
- poj3211-01背包变形
- poj3211(01背包)
- poj3211 转换 01背包
- POJ3211--分类01背包
- poj3211 Washing Clothes(多次01背包)
- poj3211 Washing Clothes(01背包)
- POJ3211:Washing Clothes(分组01背包)
- poj3211(背包dp)
- 01背包入门题解--poj3624、poj3628、hdu1864、poj3211
- poj3211(分组背包。。。大概)
- poj3211
- poj3211
- poj3211(Washing Clothes + 0/1背包)
- Washing Clothes poj3211 0-1背包
- POJ 3211 Washing Clothes【01背包+STL】
- 经典动态规划问题 背包问题 [POJ3211][POJ2063][HDU1114][POJ1276][POJ1014][POJ1742][ZOJ3631]
- POJ3211洗衣服
- WebView基本使用
- Android中Fatal signal 11 (SIGSEGV) at 0x6df6d7bf (code=2), thread 31535 问题
- 15. 3Sum
- Sigar介绍与使用
- 手机连上WIFI后,登不上电脑上的JSP网页。
- 01背包 poj3211 STL助攻
- 分区有的视图怎么自定义,如何关联xib
- 关于List中可以添加null的问题
- Linux文件属性相关知识点学习总结
- Delphi XE5 开发android环境配置
- WebView网页适配的问题
- activity中怎么控制listview adapter中生成的对话框
- monitor command not supported by this target
- Asp 中如何读取并解析 .msg 文件?