01背包问题
来源:互联网 发布:android js交互框架 编辑:程序博客网 时间:2024/06/05 06:06
#include <iostream>#include <cstring>using namespace std;const int MAX = 100;int n,W;int w[MAX],v[MAX];int book[100][100];int rec(int i,int j){ if(book[i][j] >= 0) return book[i][j]; int res;//价值 if(i == n) res = 0; else if(j < w[i]) res = rec(i+1,j); else res = max(rec(i+1,j),rec(i+1,j-w[i])+v[i]); return book[i][j] = res;}int main(){ memset(book,-1,sizeof(book)); cin>>n>>W; for(int i=1;i<=n;i++) cin>>w[i]>>v[i]; cout<<rec(0,W); return 0;}
阅读全文
0 0
- 背包问题---01背包
- DP 背包问题 01背包
- 01背包--苹果,背包问题
- 01背包 完全背包问题
- 背包问题之01背包
- 背包问题之01背包
- 背包问题1:01背包
- 背包问题《1》01背包
- 01背包+完全背包问题
- 背包问题-背包01-苹果
- 背包问题之01背包
- 背包问题(01背包,完全背包,多重背包)
- 背包问题(01背包,完全背包,多重背包)
- 动态规划-----背包问题-----01背包,完全背包,多重背包
- 经典背包问题 01背包+完全背包+多重背包
- 背包(01背包、完全背包、多重背包)问题总结
- 背包问题(01背包,完全背包,多重背包)
- 经典背包问题 01背包+完全背包+多重背包
- TensorFlow脑洞人脸识别(三)
- 最小生成树
- oracle命令
- Studio自定义发布APK 名字
- 论文笔记之:Progressive Neural Network
- 01背包问题
- Hibernate——仅更新部分字段
- Android平台快速集成当下流行平台分享
- log4j2自定义Appender(输出到文件/RPC服务中)
- 【算法课程作业说明】
- 上传代码到GitHub
- 【GamePlay3D游戏引擎学习笔记】——GamePlay3D游戏引擎VS2015搭建
- 【开发也是好测试系列】(二)——pytest之fixture
- 最长公共子序列