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 ...
随机推荐
- Django Model one
models :URL---->http://www.cnblogs.com/wupeiqi/p/6216618.html null 数据库中字段是否可以 ...
- 谋哥:搞APP,做得累的都不对!
最近谋哥(微信viyi88)我刚加入“秦王会”,思想收到猛烈地冲击,各位大佬的思维有时候会让我大脑短路,收获不少.同时,我也慢慢发现我一直平静的 心开始浮躁,我发现苗头不对,于是开始静下心来.静下心, ...
- MacOS常用软件推荐
1.效率提升神器Alfred 可以搜索文件.应用.web搜索.词典等等 链接:https://pan.baidu.com/s/1igv4tuXkuMFOPT9E6Cc5Jg 密码:3o51 软件解压密 ...
- 基于 FPGA 的图像边缘检测
本文主要内容是实现图像的边缘检测功能 目录 mif文件的制作 调用 ip 核生成rom以及在 questasim 仿真注意问题 灰度处理 均值滤波:重点是3*3 像素阵列的生成 sobel边缘检测 图 ...
- 博客笔记(blog notebook)
1. 机器学习 2. NLP 3. code 实际好人 实际坏人 预测百分比 预测好人 \(p_GF^c(s_c\|G)\) \(p_BF^c(s_c\|B)\) \(F^c(s_c)\) 预测坏人 ...
- Wannafly模拟赛2
Contest 时间限制:1秒 空间限制:131072K 题目描述 n支队伍一共参加了三场比赛. 一支队伍x认为自己比另一支队伍y强当且仅当x在至少一场比赛中比y的排名高. 求有多少组(x,y),使得 ...
- [译]__main__ 顶级脚本环境
'main'是其中顶级代码执行的范围的名称.一个模块的__name__可以从标准输入,脚本,或从一个交互式命令行中等方式被设置成等于'main'. 一个模块可以发现它是否是通过检查自身在主运行范围__ ...
- 【Luogu】P3047附近的牛(树形DP)
题目链接 树形DP,设f[i][j]是当前在i点,j步之内有多少牛.从相邻点to的f[to][j-1]转移而来,减去重复计算即可. #include<cstdio> #include< ...
- BZOJ 3626 [LNOI2014]LCA ——树链剖分
思路转化很巧妙. 首先把询问做差分. 然后发现加入一个点就把路径上的点都+1,询问的时候直接询问到根的路径和. 这样和原问题是等价的,然后树链剖分+线段树就可以做了. #include <map ...
- Miracast HDCP 等知识
Miracast 通讯架构中关于视频数据处理流程的部分.整个视频数据处理及传输的流程,大致上分为几个阶段,一开始将撷取到系统的画面及声音进行压缩,而压缩后的影音数据再转为基本封包串流(Packetiz ...