完全背包,但是总容量不稳定,随着每年的盈利,背包容量在变大,而且,题目给的数据比较大,但是给的有投资的都是1000 的倍数,运用的时候除以1000即可,附代码:
Time Limit : 5000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 2   Accepted Submission(s) : 1
Problem Description
John never knew he had a grand-uncle, until he received the notary’s letter. He learned that his late grand-uncle had gathered a lot of money, somewhere in South-America, and that John was the only inheritor.

John did not need that much money for the moment. But he realized that it would be a good idea to store this capital in a safe place, and have it grow until he decided to retire. The bank convinced him that a certain kind of bond was interesting for him.

This kind of bond has a fixed value, and gives a fixed amount of yearly interest, payed to the owner at the end of each year. The bond has no fixed term. Bonds are available in different sizes. The larger ones usually give a better interest. Soon John realized that the optimal set of bonds to buy was not trivial to figure out. Moreover, after a few years his capital would have grown, and the schedule had to be re-evaluated.

Assume the following bonds are available:
Value Annual interest
4000   400
3000   250

With a capital of $10 000 one could buy two bonds of $4 000, giving a yearly interest of $800. Buying two bonds of $3 000, and one of $4 000 is a better idea, as it gives a yearly interest of $900. After two years the capital has grown to $11 800, and it makes sense to sell a $3 000 one and buy a $4 000 one, so the annual interest grows to $1 050. This is where this story grows unlikely: the bank does not charge for buying and selling bonds. Next year the total sum is $12 850, which allows for three times $4 000, giving a yearly interest of $1 200.

Here is your problem: given an amount to begin with, a number of years, and a set of bonds with their values and interests, find out how big the amount may grow in the given period, using the best schedule for buying and selling bonds.

Input
The first line contains a single positive integer N which is the number of test cases. The test cases follow. The first line of a test case contains two positive integers: the amount to start with (at most $1 000 000), and the number of years the capital may grow (at most 40). The following line contains a single number: the number d (1 <= d <= 10) of available bonds. The next d lines each contain the description of a bond. The description of a bond consists of two positive integers: the value of the bond, and the yearly interest for that bond. The value of a bond is always a multiple of $1 000. The interest of a bond is never more than 10% of its value.
Output
For each test case, output – on a separate line – the capital at the end of the period, after an optimal schedule of buying and selling.
Sample Input
1 10000 4 2 4000 400 3000 250
Sample Output
14050
Source
NWERC2004

附代码:

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int cost[1100000],ans[1100000],i,j,k,l,m,n,gett[1100000];
int main()
{int p;scanf("%d",&p);while(p--){scanf("%d%d",&n,&m);scanf("%d",&k);for(i=1;i<=k;i++)scanf("%d%d",&cost[i],&gett[i]);memset(ans,0,sizeof(ans));int help=n;for(int x=0;x<m;x++){for(i=1;i<=k;i++){for(j=cost[i]/1000;j<=help/1000;j++)ans[j]=max(ans[j],ans[j-cost[i]/1000]+gett[i]);  }help+=ans[j-1];}printf("%d\n",help);}
}

杭电1963 完全背包相关推荐

  1. 5410 ACM 杭电 01+完全背包

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=5410 虽然是英文题目:但还是很好理解的.明显的背包问题 思路:如果你能想到把题目拆分成小问题,就会简单许多 ...

  2. 杭电1284钱币兑换问题—背包dp/母函数(java)

    Problem Description 在一个国家仅有1分,2分,3分硬币,将钱N兑换成硬币有很多种兑法.请你编程序计算出共有多少种兑法. Input 每行只有一个正整数N,N小于32768. Out ...

  3. 2022杭电多校第八场题解

    2022杭电多校第八场 Theramore(思维) 题意 给定一个01字符串,每次可以将一个奇数长度的区间翻转,求操作后字典序最小的字符串. 分析 翻转奇数长度的区间,元素位置的奇偶性不变,统计奇数位 ...

  4. 2022“杭电杯”中国大学生算法设计超级联赛(8)

    2022"杭电杯"中国大学生算法设计超级联赛(8) [题目链接](Search Result (hdu.edu.cn)) D Quel'Thalas 题目大意 在二维平面上,[0, ...

  5. hdoj杭电问题分类

    杭电上的题虽然多,但是一直苦于找不到问题分类,网页都是英文的,所以平时做题也没怎么看,今天仔细一看,问题分类竟然就在主页....做了那么久的题居然没发现,表示已经狗带..不要笑,不知道有没有像我一样傻 ...

  6. 杭电46道DP牛人总结

    原文地址:杭电46道DP牛人总结作者:飞泉鸣玉 杭电46道DP牛人总结 HDU 动态规划(46道题目)倾情奉献~ [只提供思路与状态转移方程] 收藏 Robberies http://acm.hdu. ...

  7. 2022“杭电杯”中国大学生算法设计超级联赛 (1) 杭电多校第一场 2 3 4 5 8 12

    题目 1002 Dragon slayer 标程 1003 Backpack AC代码 1004 Ball AC代码 1008 Path AC代码 1009 Laser AC代码 1012 Alice ...

  8. 杭电60道DP问题总结(一)

    杭电60道DP问题总结: DP是一个很有艺术的思想.看似简单的背后却隐藏着深刻的含义. 题目连接地址:http://acm.hdu.edu.cn/problemclass.php?id=516& ...

  9. 2022杭电多校(一)

    2022杭电多校(一) 文章目录 2022杭电多校(一) 一.比赛小结 二.题目分析及解法(基础题) 1001.String 1002.Dragon slayer 1003.BackPack 1004 ...

最新文章

  1. 利用CGMutablePathRef制作画板涂鸦
  2. Linux System and Performance Monitoring
  3. linux查看目录文件系统,ubuntu linux 文件系统目录结构-Windows下查看电脑信息的命令-linux菜鸟也必须知道的几个ubuntu最基础命令_169IT.COM...
  4. Python 爬虫浏览器伪装技术
  5. 推荐系统炼丹笔记:Embedding在内存问题上的一种解法
  6. 状态压缩 DP AHU420
  7. python软件是什么原因引起的_Python对程序员重要的原因在哪里?
  8. mysql 清理 reley_MySQL日志相关
  9. 使用JS实现将GridView中的TextBox列的值博给GridView外的一个文本筐
  10. java常用类解析五:IO系统File类及文件搜索工具类
  11. kvm虚拟机设置万兆网卡_kvm已经设置桥接网卡的虚拟机无法连接宿主机?
  12. 【机器学习】KNN回归
  13. 一个农民工学习LINUX内核的艰辛历程/嵌入式的感受
  14. CodeForces 173B Chamber of Secrets(最短路)
  15. 管理感悟:主管加班,员工才会加班
  16. 21天学通JAVA——学习笔记
  17. [sprd]Android Q修改 Launcher 上文件夹图标的大小和应用的图标大小一致
  18. [HTML]北京邮电大学信息与通信工程学院选课参考指南
  19. linux教程试卷_linux基础教程试卷及答案.doc
  20. 2016年我国网络安全态势

热门文章

  1. logistics回归多样本算法
  2. 随机森林 Random Forest
  3. 浅谈:云桌面在我国高校的应用前景
  4. Linux shell中比较操作符“==”与“-eq”对比
  5. shell脚本--判断输入的ip是否正确
  6. 数据库sql server 2008安装。
  7. swagger ui 值类型形参加文字注释
  8. SharePoint 删除废弃站点步骤
  9. JS让文本以打字效果呈现出来
  10. kotlin gradle的修改