1034: 采药

来源:互联网 发布:mac搜狗输入法怎么设置 编辑:程序博客网 时间:2024/05/18 20:06

0/1背包问题点击打开链接http://sdnuacm.sinaapp.com/problem.php?id=1034

#include<iostream>using namespace std;int main(){int m,n,w,v;int F[1010]={0};cin>>m>>n;for(int i=1;i<=n;i++){cin>>w>>v;for(int k=m;k>=w;k--){if(F[k]<F[k-w]+v)F[k]=F[k-w]+v;}}cout<<F[m]<<endl;return 0;}