博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 2063 (DP)
阅读量:4692 次
发布时间:2019-06-09

本文共 1153 字,大约阅读时间需要 3 分钟。

题目:

 

完全背包,参考背包九讲第二讲:

 

bond看成重量,interest看成价值,本金看成背包容量。

 

注意三点:

(1)本金每年不一样,更新;

(2)本金,债券都是1000的倍数,除以1000减少循环次数,是大大减少;

(3)本金的循环是从某债券到本金递增,不能搞反了。

 

代码:

#include 
#include
#include
int f[50000];int bond[11],interest[11]; int main(){ int T,i,j,n,ans,tmp,t,start,year; scanf("%d",&T); do { scanf("%d%d",&start,&year); scanf("%d",&n); memset(f,0,sizeof(f)); for(i = 0 ; i < n ; ++i) { scanf("%d%d",bond+i,interest+i); bond[i] /= 1000; } while(year--) { tmp = start; tmp /= 1000; for(i = 0 ; i < n ; ++i) for(j = bond[i] ; j <= tmp ; ++j) // for(j = tmp ; j >= bond[i] ; --j) { t = f[j-bond[i]] + interest[i]; if(t > f[j]) f[j] = t; } start += f[tmp]; } printf("%d\n",start); }while(--T); //system("pause"); return 0; }

 

 

转载于:https://www.cnblogs.com/HpuAcmer/archive/2012/05/09/2492818.html

你可能感兴趣的文章
Android_去掉EditText控件周围橙色高亮区域
查看>>
《构建之法》第一、二、十六章阅读笔记
查看>>
arrow:让Python的日期与时间变的更好
查看>>
(转)Excel的 OleDb 连接串的格式(连接Excel 2003-2013)
查看>>
Java并发编程
查看>>
Git Stash用法
查看>>
sql server 2008学习8 sql server存储和索引结构
查看>>
Jquery radio选中
查看>>
postgressql数据库中limit offset使用
查看>>
测试思想-集成测试 关于接口测试 Part 2
查看>>
windows下mysql密码忘了怎么办?【转】
查看>>
php生成器使用总结
查看>>
T-SQL中的indexof函数
查看>>
javascript基础之数组(Array)对象
查看>>
mysql DML DDL DCL
查看>>
RAMPS1.4 3d打印控制板接线与测试1
查看>>
python with语句中的变量有作用域吗?
查看>>
24@Servlet_day03
查看>>
初级ant的学习
查看>>
redis数据结构--String
查看>>