sicily 1342 (0/1背包问题)
来源:互联网 发布:多多印 知乎 编辑:程序博客网 时间:2024/06/08 04:42
//首次接触背包问题,理解起来还是有点吃力!需要多练习!
#include "iostream"#include "cmath"using namespace std;int total[26][300010];int main(){int N, m;while (cin >> N >> m){int *price = new int[m+1];int *degree = new int[m+1];for (int i = 0; i <= m; i++)for (int j = 0; j <= N; j++)total[i][j] = 0;for (int i = 1; i <= m; i++)cin >> price[i] >> degree[i];int ans = 0;for (int i = 1; i <= m; i++)for (int j = 1; j <= N; j++){if (price[i] <= j){if (total[i-1][j] < total[i-1][j-price[i]] + price[i] * degree[i])//动态规划的公式!要理解透,熟悉运用!{total[i][j] = total[i-1][j-price[i]] + price[i] * degree[i]; ans = max(total[i][j], ans);}else{total[i][j] = total[i-1][j];ans = max(total[i][j], ans);}}else {total[i][j] = total[i-1][j];ans = max(total[i][j], ans);}}cout << ans << endl;}}
- sicily 1342 (0/1背包问题)
- [sicily online]1146. 采药(0-1背包)
- 背包问题(二):0-1背包
- (背包一)0-1背包问题
- 背包问题(0/1背包,完全背包)
- [Sicily Coins] 动态规划 多重背包问题
- 0-1背包问题、背包问题(贪心算法)
- 贪心法--背包问题(不是0/1背包问题)
- 【转】背包问题总结(0-1背包+完全背包+多重背包)
- 背包问题总结(0-1背包+完全背包+多重背包)
- 【转】背包问题总结(0-1背包+完全背包+多重背包)
- 背包问题 (0-1背包,多重背包,完全背包)
- 模板①:背包问题(0-1背包&完全背包&多重背包)
- 动态规划--背包问题(0-1背包,完全背包,多重背包)
- 背包问题(0-1背包、完全背包、多重背包)详解
- Sicily 1346 金明的预算方案 (SOJ 1346) 【DP 动态规划-背包问题】
- 背包问题和0-1背包问题
- 背包问题和0-1背包问题
- RMXP for android
- UIImagePickerController之死因
- C#Socket基本编程
- hadoop初学之WordCount程序一步一步运行
- IIs Web 站点安全 监控 站点自动部署 重启
- sicily 1342 (0/1背包问题)
- iphone开发-SQLite数据库使用
- 找不到php_mbstring.dll或php_exif.dll的解决方法与mb_系列函数的用法 libmcrypt.dll时出错的处理
- iphone 开发开放库-ASIHTTPRequest类库简介和使用说明
- hibernate 主键自增
- 提供常量_转_变量的适配器
- Linux--常用命令--date
- Linux设备模型<二>底层模型
- 程序什么时候应该使用线程,什么时候单线程效率高