51nod--1085--背包问题
来源:互联网 发布:51单片机控制机箱风扇 编辑:程序博客网 时间:2024/06/07 22:59
题目链接:
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1085
代码:
#include<iostream>#include<cstdio>#include<algorithm>using namespace std;const int MAX=1e5+10;int dp[105][MAX];int wi[MAX];int pi[MAX];int main(){ int w,n; cin>>n>>w; for(int i=0;i<=n;i++) dp[i][0]=0; for(int j=0;j<=w;j++) dp[0][j]=0; for(int i=1;i<=n;i++) cin>>wi[i]>>pi[i]; for(int i=1;i<=n;i++) { for(int j=0;j<=w;j++) { if(j<wi[i]) dp[i][j]=dp[i-1][j]; else { dp[i][j]=max(dp[i-1][j],dp[i-1][j-wi[i]]+pi[i]); } } } cout<<dp[n][w]<<endl; return 0;}
阅读全文
0 0
- 51nod 1085 背包问题
- 51nod 1085 背包问题
- 51Nod--1085背包问题
- 51nod 1085 背包问题
- 51Nod 1085 背包问题
- 51Nod 1085 背包问题
- 51nod 1085 背包问题
- 51nod 1085 背包问题
- 【51nod 1085 背包问题】
- 51nod 1085 背包问题
- 51Nod-1085 背包问题
- 51nod--1085--背包问题
- 51nod 1085 背包问题
- 51Nod 1085 背包问题
- 51nod 1085 背包问题【01背包】
- 51nod 1085 背包问题【01背包】
- 51nod-1085 背包问题【01背包】
- 背包问题-----51Nod
- C#使用MonoPInvokeCallback,让C直接回调C#函数
- SpringBoots的使用
- Oracle中rank() over, dense_rank(), row_number() 的区别
- openstack安装rabbitmq时查看rabbitmq插件出现failed to connect rabbitmq@controller
- Struts2中action三种方式
- 51nod--1085--背包问题
- 格式良好的XML文档( well formed)
- unity手势插件《FingerGestures 》使用入门
- Python与数据结构总结(一)
- 项目3 求集合并集
- [codefoces2017-2018 ACM-ICPC]刷题小练
- P3793礼物和糖果
- GitBook Editor不能pull新Book时的处理
- 知识点记录之Integer