POJ 2063 Investment (完全背包)
Time Limit:1000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64u
Description
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 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
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 <stdio.h>
#include <string.h> #define N 50006 int dp[N], w[N], p[N]; int max(int a, int b)
{
return a > b ? a : b;
} int main()
{
int t;
int aa, yy, d;
int n, v, i, k; scanf("%d", &t); while(t--)
{
scanf("%d %d", &aa, &yy);
scanf("%d", &d); for(i=1; i<=d; i++)
{
scanf("%d %d", &p[i], &w[i] );//花费 收入
p[i] = p[i]/1000;
}
n = d;//种类 while(yy--)
{
memset(dp, 0, sizeof(dp));
v = aa/1000;
for(i=1; i<=n; i++)
{
for(k=0; k<=v; k++)
{
if( k>=p[i] )
dp[k] = max (dp[k], dp[k-p[i]]+w[i] );
}
} aa = aa+dp[v]; }
printf("%d\n", aa );
}
}
POJ 2063 Investment (完全背包)的更多相关文章
- POJ 2063 Investment 完全背包
题目链接:http://poj.org/problem?id=2063 今天果然是卡题的一天.白天被hdu那道01背包的变形卡到现在还没想通就不说了,然后晚上又被这道有个不大也不小的坑的完全背包卡了好 ...
- POJ 2063 Investment 滚动数组+完全背包
题目链接: http://poj.org/problem?id=2063 题意: 你现在有现金m元,你要做n年的存款投资,给你k种投资方式,每种需要现金vi元,能获得xi元的理论,一年到期后你要利用拿 ...
- poj 2063 Investment ( zoj 2224 Investment ) 完全背包
传送门: POJ:http://poj.org/problem?id=2063 ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problem ...
- poj 2063 Investmen 完全背包
这个题的想法不难,两个点: 1 是完全背包 2 是考虑/1000,降低复杂度 但是提交的时候反复的wa,最后找问题原来是dp开小了,可是dp本来开1005,后来开到100030过了.哎,如果没有时 ...
- [POJ 2063] Investment (动态规划)
题目链接:http://poj.org/problem?id=2063 题意:银行每年提供d种债券,每种债券需要付出p[i]块钱,然后一年的收入是v[i],到期后我们把本金+收入取出来作为下一年度本金 ...
- poj 2063 Investment
题意:给定一个初始资金capital,然后给定d种投资方案,每种投资方案中有投资额value[i](是1000的倍数)和利息interest[i],每年的投资就可以拿到全部利息,然后累加起来继续投资利 ...
- 专题复习--背包问题+例题(HDU 2602 、POJ 2063、 POJ 1787、 UVA 674 、UVA 147)
*注 虽然没什么人看我的博客但我还是要认认真真写给自己看 背包问题应用场景给定 n 种物品和一个背包.物品 i 的重量是 w i ,其价值为 v i ,背包的容量为C.应该如何选择装入背包中的物品,使 ...
- poj 2063完全背包
题意:给出总资金和投资年份 ,n个股票 给出股票价格和其一年的利润.问如何选择能获得最大利润. 思路:股票可以重复选择,完全背包问题,完全背包也是从01背包衍生而行的,其主要区别在于中间那层循环的次序 ...
- POJ 1155 (树形DP+背包+优化)
题目链接: http://poj.org/problem?id=1155 题目大意:电视台转播节目.对于每个根,其子结点可能是用户,也可能是中转站.但是用户肯定是叶子结点.传到中转站或是用户都要花钱, ...
随机推荐
- 【前端阅读】——《JavaScript应用开发技术详解指南》摘记&思维导图
读这本书,我主要关注三个部分:JavaScript内置函数,程序调试以及Ajax基础.由于多是介绍基本概念,所以,采用思维导图的方式,做了一个梳理,以下就是精简的主要内容. 注:转载请注明出处
- js 考记忆力得小游戏
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Solidworks如何生成爆炸图
1 自动爆炸 点击"爆炸视图"按钮,然后全部选中装配体(被选中的零件会变为蓝色,全部选中即全部变色)然后在组成偶尔的爆炸窗口中下拉,点击应用. 再点击完成 回到装配体面板, ...
- 【X240 QQ视频对方听不到声音】解决方法
[X240 QQ视频对方听不到声音]解决方法: win7为例: 右键点击右下角的"小喇叭"图标,点击"录音设备",显演示样例如以下图: watermark/2/ ...
- Nook 2 Root
最后我还是忍不住root了它,用了差一点够一个月 1.备份2.root 3.装软件=====================================================1. ...
- Buck电路匹配和二极管仿真模式
Buck带同步整流,关闭二极管仿真模式会使空载损耗大 利用二极管仿真模式提高降压转换器轻负载效率 Buck电路工作原理以及三种工作模式分析 一.Buck电路原理图 Buck电路,又称降压电路,其基 ...
- Linux NAT网络连接权威指南
[1]准备工作,写在前面 1.1)检查服务(cmd>>services.msc,我用的是VM) 1.2)确保Vmnet8 连接处于启动状态 + 获取ipv4(ipv6)地址 (在网络连接不 ...
- 3_Jsp标签_简单标签_防盗链和转义标签的实现
一概念 1防盗链 在HTTP协议中,有一个表头字段叫referer,采用URL的格式来表示从哪儿链接到当前的网页或文件,通过referer,网站可以检测目标网页访问的来源网页.有了referer跟踪来 ...
- 通过srvctl add命令添加database信息到srvctl管理器
================================================通过srvctl add命令添加database信息到srvctl管理器================ ...
- iOS对象(数组)转化为JSon字符串
- (void)seabc { NSArray *arry=[NSArray arrayWithObjects:@"0081",@"0082",@"0 ...