poj 2063 Investment(完全背包)
来源:互联网 发布:java 查看线程状态 编辑:程序博客网 时间:2024/05/22 10:29
多次完全背包
要对背包的容量进行压缩,不然超内存
因为债券的价格都是1000的倍数,就除1000来压缩
#include <stdio.h>#include <string.h>#define max(a,b) (a)>(b)?(a):(b)int w[15];int v[15];int dp[50000];int W,n;void solve(){ for(int i = 0; i < n; ++i) for(int j = w[i]; j <= W; ++j) dp[j] = max(dp[j],dp[j-w[i]]+v[i]);}int main(){ int T,y,sum; scanf("%d",&T); while(T--) { scanf("%d %d",&sum,&y); scanf("%d",&n); for(int i = 0; i < n; ++i) { scanf("%d %d",&w[i],&v[i]); w[i] /= 1000; } while(y--) { W = sum/1000; memset(dp,0,sizeof(dp)); solve(); sum += dp[W]; } printf("%d\n",sum); } return 0;}
阅读全文
0 0
- POJ 2063 Investment (完全背包)
- POJ 2063 Investment DP(完全背包)
- POJ 2063 Investment(完全背包)
- POJ 2063 Investment(完全背包)
- POJ 2063Investment(完全背包)
- POJ 2063 - Investment(完全背包)
- POJ 2063 Investment(完全背包)
- POJ 2063 Investment (完全背包)
- POJ 2063 Investment(完全背包问题)
- POJ 2063 Investment(完全背包)
- poj 2063 Investment(完全背包)
- poj 2063 Investment 完全背包
- Poj 2063 Investment (完全背包)
- POJ 2063 Investment 完全背包
- poj 2063 Investment 完全背包
- poj 2063 Investment (完全背包)
- POJ 2063 Investment 完全背包
- POJ 2063 Investment 完全背包
- 为什么使用MQ
- 爬虫实践---Scrapy-爬取慕课网热门课程
- SVM入门(五)线性分类器的求解——问题的描述Part2
- hpuoj【1389】梦想从A+B开始【水题】&&【转义字符的输出】
- Java中如何遍历Map对象的4种方法
- poj 2063 Investment(完全背包)
- Android Binder 修炼之道(四)Binder 系统C++ 发送数据过程以及Server注册服务处理数据的过程
- HDU 4812 D Tree (2013-南京 树分治 + 逆元 + 离散化)
- jdk源码分析--Enum
- Android判断网线连接
- 欢迎使用CSDN-markdown编辑器
- hdu6105(博弈)
- 互联网领域 软件领域 必备技能
- 权利的游戏-三眼乌鸦喝水算法Aesop's Fables