G 全然背包
<span style="color:#3333ff;">/* /*
__________________________________________________________________________________________________
* copyright: Grant Yuan *
* algorithm: 全然背包 *
* time : 2014.7.18 *
*_________________________________________________________________________________________________*
G - 全然背包
Time Limit:1000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64u
Submit Status
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
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<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std; int sm,y,t,n,d,m;
int a[1111],b[1111];
int dp[200000]; int main()
{
cin>>t;
while(t--){
cin>>sm>>y;cin>>n;
for(int i=0;i<n;i++)
{
cin>>d>>b[i];
a[i]=d/1000;} for(int i=0;i<y;i++){
m=sm;m=m/1000;
memset(dp,0,sizeof(dp));
for(int j=0;j<n;j++)
for(int k=a[j];k<=m;k++){
dp[k]=max(dp[k],dp[k-a[j]]+b[j]);
}
sm+=dp[m];}
cout<<sm<<endl;
}
return 0;
}
</span>
G 全然背包的更多相关文章
- HDU 1248寒冰王座-全然背包或记忆化搜索
寒冰王座 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
- HDU 1248 寒冰王座(全然背包:入门题)
HDU 1248 寒冰王座(全然背包:入门题) http://acm.hdu.edu.cn/showproblem.php?pid=1248 题意: 不死族的巫妖王发工资拉,死亡骑士拿到一张N元的钞票 ...
- HDU 4508 湫湫系列故事——减肥记I(全然背包)
HDU 4508 湫湫系列故事--减肥记I(全然背包) http://acm.hdu.edu.cn/showproblem.php?pid=4508 题意: 有n种食物, 每种食物吃了能获得val[i ...
- A_全然背包
/* copyright: Grant Yuan algorithm: 全然背包 time : 2014.7.18 __________________________________________ ...
- nyist oj 311 全然背包 (动态规划经典题)
全然背包 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描写叙述 直接说题意,全然背包定义有N种物品和一个容量为V的背包.每种物品都有无限件可用.第i种物品的体积是c,价值是 ...
- HDU 1114 Piggy-Bank 全然背包
Piggy-Bank Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit S ...
- poj 1384 Piggy-Bank(全然背包)
http://poj.org/problem?id=1384 Piggy-Bank Time Limit: 1000MS Memory Limit: 10000K Total Submissions: ...
- UVA 10465 Homer Simpson(全然背包: 二维目标条件)
UVA 10465 Homer Simpson(全然背包: 二维目标条件) http://uva.onlinejudge.org/index.php? option=com_onlinejudge&a ...
- [2012山东ACM省赛] Pick apples (贪心,全然背包,枚举)
Pick apples Time Limit: 1000MS Memory limit: 165536K 题目描写叙述 Once ago, there is a mystery yard which ...
随机推荐
- [转] 查看 SELinux状态及关闭SELinux
本文转载自: http://bguncle.blog.51cto.com/3184079/957315 查看SELinux状态: 1./usr/sbin/sestatus -v ##如果SE ...
- tab选项卡不同样式的效果
一般的tab选项卡就只能两种样式,一种是选中或者是划过这个选项卡样式,一种是没选中或者没划过选项卡样式. 现在有这种需求,就是选中或划过tab选卡要不同样式.比如tab1选中或者划过是红色,tab2选 ...
- Leetcode39--->Combination Sum(在数组中找出和为target的组合)
题目: 给定一个数组candidates和一个目标值target,求出数组中相加结果为target的数字组合: 举例: For example, given candidate set [2, 3, ...
- Leetcode4--->求两个排序数组的中位数
题目:给定两个排序数组,求两个排序数组的中位数,要求时间复杂度为O(log(m+n)) 举例: Example 1: nums1 = [1, 3] nums2 = [2] The median is ...
- python 学习分享-字典篇
python字典(Dictionary) dict是无序的 key必须是唯一切不可变的 a={'key1':'value1','key2':'value2'} 字典的增删改查 a['key3']='v ...
- Python字典类型、
字典类型: # msg_dic = {# 'apple': 10,# 'tesla': 100000,# 'mac': 3000,# 'lenovo': 30000,# ...
- ibatis 动态SQL
直接使用JDBC一个非常普遍的问题就是动态SQL.使用参数值.参数本身和数据列都是动态SQL,通常是非常困难的.典型的解决办法就是用上一堆的IF-ELSE条件语句和一连串的字符串连接.对于这个问题,I ...
- DS博客作业05—树
1.本周学习总结 1.1思维导图 1.2学习体会 本周学习了树的相关知识,了解了树结构体的应用和基本操作 学习了二叉树的遍历,创建以及哈夫曼树的相关操作 通过树的构建等操作熟练了递归的使用 2.PTA ...
- hibernate与struts框架实现增删改查
这里配置hibernate与struts不再过多赘述,配置搭建前文已经详细讲解,配置如下: hibernate.hbm.xml配置: <?xml version="1.0" ...
- P2730 魔板 Magic Squares (搜索)
题目链接 Solution 这道题,我是用 \(map\) 做的. 具体实现,我们用一个 \(string\) 类型表示任意一种情况. 可以知道,排列最多只有 \(8!\) 个. 然后就是直接的广搜了 ...