51Nod 1085 背包问题(01)
2017-09-03 12:44
274 查看
题目链接
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
using namespace std;
int main(){
int n,w;
cin>>n>>w;
int we[1001],v[1001];
for(int i=0;i<n;i++){
cin>>we[i]>>v[i];
}
int f[10001]={0};
for(int i=0;i<n;i++){
for(int j=w;j>=we[i];j--){
f[j]=max(f[j],f[j-we[i]]+v[i]);
}
}
cout<<f[w];
return 0;
}
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
using namespace std;
int main(){
int n,w;
cin>>n>>w;
int we[1001],v[1001];
for(int i=0;i<n;i++){
cin>>we[i]>>v[i];
}
int f[10001]={0};
for(int i=0;i<n;i++){
for(int j=w;j>=we[i];j--){
f[j]=max(f[j],f[j-we[i]]+v[i]);
}
}
cout<<f[w];
return 0;
}
相关文章推荐
- 51nod 1085 背包问题01
- 51Nod-1085-背包问题
- 【51nod 1085】背包问题(0-1背包模板)
- 51nod 1085 背包问题
- 51Nod 1085背包问题(dp)
- 01背包基础-1085 背包问题
- 51Nod:1085 背包问题
- 51nod--1085--背包问题
- 51Nod 1085 背包问题
- 51nod 1085 01背包
- 【51NOD-0】1085 背包问题
- 51Nod 1085 背包问题(01背包 )
- 51Nod-1085 背包问题
- 51nod 1085 背包问题
- 51nod 1085 背包问题【01背包】
- 51Nod 1085 背包问题
- 51Nod-1085-背包问题
- 51Nod 1085 背包问题
- 51nod 1085 背包问题(01背包)
- 51nod1085---背包问题(51nod基础:01背包)