个人心得:炸了炸了,这背包什么的脑阔痛。

完全背包什么鬼咯,状态正向转移与01背包正好相反。

二维数组的状态转移。

一维数组的优化,注意正向覆盖。

本题中的思想

 for(int y=;y<=year;y++){
int s=cash/;
for(int i=;i<=n;i++){
for(int j=bond[i];j<=s;j++){
dp[j]=max(dp[j],dp[j-bond[i]]+gain[i]);
}
}
cash+=dp[s];
}
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
3000
400
250

With a capital of e10 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
 #include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
const int money=;
const int MAXN=;
int bond[],gain[];
int dp[];
int main(){
int t;
cin>>t;
while(t--){
int cash,year,n;
cin>>cash>>year>>n;
memset(dp,,sizeof(dp));
for(int i=;i<=n;i++)
{
cin>>bond[i]>>gain[i];
bond[i]/=money;
}
int k,ans;
for(int y=;y<=year;y++){
int s=cash/;
for(int i=;i<=n;i++){
for(int j=bond[i];j<=s;j++){
dp[j]=max(dp[j],dp[j-bond[i]]+gain[i]);
}
}
cash+=dp[s];
}
cout<<cash<<endl;
}
return ;
}
												

Investment(完全背包)的更多相关文章

  1. POJ 2063 Investment 完全背包

    题目链接:http://poj.org/problem?id=2063 今天果然是卡题的一天.白天被hdu那道01背包的变形卡到现在还没想通就不说了,然后晚上又被这道有个不大也不小的坑的完全背包卡了好 ...

  2. hdu 1963 Investment 多重背包

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1963 //多重背包 #include <cstdio> #include <cstr ...

  3. HDU1963 && POJ2063:Investment(完全背包)

    Problem Description John never knew he had a grand-uncle, until he received the notary’s letter. He ...

  4. poj 2063 Investment ( zoj 2224 Investment ) 完全背包

    传送门: POJ:http://poj.org/problem?id=2063 ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problem ...

  5. poj分类解题报告索引

    图论 图论解题报告索引 DFS poj1321 - 棋盘问题 poj1416 - Shredding Company poj2676 - Sudoku poj2488 - A Knight's Jou ...

  6. POJ2063 Investment 【全然背包】

    Investment Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 8019   Accepted: 2747 Descri ...

  7. poj2063 Investment(多次完全背包)

    http://poj.org/problem?id=2063 多次完全背包~ #include <stdio.h> #include <string.h> #define MA ...

  8. POJ 2063 Investment 滚动数组+完全背包

    题目链接: http://poj.org/problem?id=2063 题意: 你现在有现金m元,你要做n年的存款投资,给你k种投资方式,每种需要现金vi元,能获得xi元的理论,一年到期后你要利用拿 ...

  9. POJ 2063 Investment (完全背包)

    A - Investment Time Limit:1000MS     Memory Limit:30000KB     64bit IO Format:%I64d & %I64u Subm ...

随机推荐

  1. LVS 命令使用

    LVS 命令使用 查询命令 ipvsadm -L # 查看lvs负载均衡信息ipvsadm -L -n # -n 查看IP端口ipvsadm -L -c   # 显示当前连接ipvsadm -L -- ...

  2. Oracle基本概念

    1. 数据库和实例 什么是数据库,其实很简单,数据库就是存储数据的一种媒介.比如常用的文件就是一种,在Oracle10g中,数据的存储有好几种.第一种是文件形 式,也就是在你的磁盘中创建一批文件,然后 ...

  3. Eclipse开发快捷键精选

    1.alt+?或alt+/:自动补全代码或者提示代码2.ctrl+o:快速outline视图3.ctrl+shift+r:打开资源列表4.ctrl+shift+f:格式化代码5.ctrl+e:快速转换 ...

  4. Linux自定义别名alias重启失效问题

    Linux上的别名功能非常方便,例如ll可以显示文件列表的长信息,但是却不是以human能读懂的方式显示,所以我尝试直接在命令行中自定义一个别名: alisa lk='ls -lh' 然后lk就能正常 ...

  5. 【P1274】魔术数字游戏(搜索+剪枝+模拟)

    做完了这个题的我一口老血喷在屏幕上... 这个题难度不高(~~胡扯~~),就是爆搜就可以了,然而..判断条件灰常多,剪枝也就非常多..然而,这些判断条件又不得不必须满足,所以也就十分容易错... 说一 ...

  6. hadoop 指定 key value分隔符

    原文:http://wingmzy.iteye.com/blog/1260570 hadoop中的map-reduce是处理<key,value>这样的键值对,故指定<key,val ...

  7. BZOJ 1941 kd-tree

    模板题 题意说的可能有点不清楚 一开始的点必须在给定的n个点里面 所以枚举点 然后ask最大和最小值 估价函数中 最大值的写法和最小值不同 全部取max 而最小值在估价时 如果在某个点管辖的空间里 就 ...

  8. 简学Python第五章__模块介绍,常用内置模块

    Python第五章__模块介绍,常用内置模块 欢迎加入Linux_Python学习群  群号:478616847 目录: 模块与导入介绍 包的介绍 time &datetime模块 rando ...

  9. Python之异常总结

    一.异常错误 a.语法错误 错误一: if 错误二: def text: pass 错误三: print(sjds b.逻辑错误 #用户输入不完整(比如输入为空)或者输入非法(输入不是数字) num= ...

  10. 添加语句<tx:annotation-driven transaction-manager="txManager"/>报错

    在添加<tx:annotation-driven transaction-manager="txManager"/>程序之前,applicationContext.xm ...