POJ 2063 Investment
来源:互联网 发布:mac双系统删除windows 编辑:程序博客网 时间:2024/06/11 17:42
题目链接:http://poj.org/problem?id=2063
题目大意:自己有一大笔钱需要通过买债券的形式存银行,有很多种债券,问在n年之内,要怎么买才能得到最大的价值。重要的一点是钱都是1000的倍数,这能对代码进行优化。
稍加分析便会发现这是一个完全背包,只不过多了一个年份属性,只需要每一年之内进行一次完全背包最大价值的计算,然后每年更新本金即可。
刚刚开始由于计算失误,导致数组开小了一小点,结果WA了(TAT,一般数组开小了,OJ都会报runtime error),检查了好几遍代码,都没错,最后发现居然是这个问题。。碉堡了。。。
代码:
#include <iostream>#include <cstdio>#include <cstring>using namespace std;int max(int a,int b){ return a>b?a:b;}int w[11];int d[11];int dp[0005];int main(){int T; int M,year,N,Mtemp;scanf("%d",&T);while(T--){scanf("%d%d%d",&M,&year,&N);for(int i=0;i<N;i++) {scanf("%d%d",&w[i],&d[i]); w[i]/=1000; } Mtemp=0; for(int k=0;k<year;k++) { memset(dp,0,sizeof(dp)); Mtemp=M/1000; for(int i=1;i<=N;i++) for(int j=w[i];j<=Mtemp;j++) dp[j]=max(dp[j],dp[j-w[i]]+d[i]); M+=dp[Mtemp]; } printf("%d\n",M);}return 0;}
0 0
- poj 2063 Investment
- POJ 2063 Investment
- poj 2063 Investment
- POJ 2063 Investment
- POJ 2063 Investment
- 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 背包
- samba服务器的搭建(scurity=share)
- 第七章 快速排序
- HDU 1598 find the most comfortable road
- 关于计时器NSTimer 的使用
- Android菜鸟在成长—ListView复杂列表信息项
- POJ 2063 Investment
- [Android]ListView性能优化之视图缓存
- oracle导入导出
- 点评圈内云战略--东软篇
- 类对象和类指针的区别
- 深入内存分析String对象的创建过程
- 从OpenCV2的Mat说起
- 收录 Uboot 详解
- 妙味课堂Javascript全套视频课程【33讲】