hihocoder 01背包问题
来源:互联网 发布:金蝶数据导入导出接口 编辑:程序博客网 时间:2024/05/22 06:52
#include<iostream>using namespace std;int valueMax[501][100001];int valueNeed[1001];int need[200001];void knap(int n, int m);int main(){int N, M;while(cin>>N>>M){ for (int i = 1; i<=N; i++){cin >> need[i];cin >> valueNeed[i];}knap(N, M);cout << valueMax[N][M] << endl;} return 0;}void knap(int n, int value){int i, j;for (i = 0; i <= n; i++){valueMax[i][0] = 0;}for (j = 0; j <= value; j++){valueMax[0][j] = 0;}for (i = 1; i <= n; i++)for (j = 1; j <= value; j++){if (j<need[i]){valueMax[i][j] = valueMax[i - 1][j];continue;}if (valueMax[i - 1][j] >= valueMax[i - 1][j - need[i]] + valueNeed[i])valueMax[i][j] = valueMax[i - 1][j];elsevalueMax[i][j] = valueMax[i - 1][j - need[i]] + valueNeed[i];}}
姐姐发现,wrong ans 原因四,数组大小刚好是hiho上声称的最大容量。于是多加上一个1就对了。。。。以上代码AC hiahia
0 0
- hihocoder 01背包问题
- HihoCoder第六周:01背包问题
- hihocoder:01背包
- hihoCoder 1038 01背包
- 01背包***hihocoder
- hihoCoder 1038 : 01背包
- hihoCoder#1038 : 01背包
- hihoCoder - 1038 - 01背包
- hihocoder之01背包
- hihoCoder 1038 01背包
- hihoCoder 1038 01背包
- hihocoder #1038 : 01背包
- hihoCoder #1038 : 01背包
- [HihoCoder]#1038 : 01背包
- Hihocoder #1038 : 01背包
- hihocoder 1038 : 01背包
- hihocoder 1038 01背包
- hihoCoder 1038 : 01背包
- eclipse识别不了模拟器解决办法
- Oracle 子查询
- ABAP SELECT-INTO用法
- Checkbox的多选简单实现(-)
- HDU2089 不要62
- hihocoder 01背包问题
- 第六章 上机3
- 第六章上机练习3 美容热点产品列表(1)
- 防御式编程思考
- FileNotFoundExceptionLibrary/Caches/AndroidStudio2.2/caches/contentHashes.dat.keystream.len (No such
- OBS源码阅读笔记--绿化配置文件路径
- Spring JPA Data Auditing
- unable to create Debug Bridge...连接不上真机调试
- oracle运行exp命令导出数据库