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 题目大意:电视台转播节目.对于每个根,其子结点可能是用户,也可能是中转站.但是用户肯定是叶子结点.传到中转站或是用户都要花钱, ...
随机推荐
- css:html() text() val()
转http://www.jb51.net/article/35867.htm .html()用为读取和修改元素的HTML标签 对应js中的innerHTML .html()是用来读取元素的HTM ...
- 总结java编程常用的快捷键
Eclipse 常用快捷键 Eclipse的编辑功能非常强大,掌握了Eclipse快捷键功能,能够大大提高开发效率.Eclipse中有如下一些和编辑相关的快捷键. 1. [ALT+/] 此快捷键为用户 ...
- ASP.NET MVC 扩展自定义视图引擎支持多模板&动态换肤skins机制
ASP.NET mvc的razor视图引擎是一个非常好的.NET MVC 框架内置的视图引擎.一般情况我们使用.NET MVC框架为我们提供的这个Razor视图引擎就足够了.但是有时我们想在我们的 ...
- SQL Server常用系统表
1.查询当前数据库中的用户表 select *from sysobjects where xtype='U'; 2.获取SQL Server允许同时用户连接的最大数 SELECT @@MAX_CONN ...
- Android微信分享功能实例+demo
Android微信分享功能实例 1 微信开放平台注册 2 获得appId,添加到程序中,并运行程序 3 使用应用签名apk生成签名,添加到微信开放平台应用签名,完成注册 4 测试分享功能. 有问题请留 ...
- 单点登录系统cas资料汇总
http://jasig.github.io/cas/4.0.x/index.html 主页 https://jasigcas.herokuapp.com ...
- Source-php-request-2
php比較坑的地方就是实现相同的目的,能够使用超级多种手段.比方(file_get_contents和fopen以及如今提到的curl以及fsockopen当然还有socket)这对于一个经验少的程序 ...
- 关于cocos2d-x 和安卓之间的相互调用
近期在研究cocos2d游戏移植安卓须要调用非常多方法.所以在研究之中写下它们之间相互调用 首先,cocos2d调用安卓 在一个.h文件里加入头文件 #include <jni.h> #i ...
- jquery插件获取事件类型
//需要在使用函数时传入event关键字 $('[name=lprice]').change(function(event){ $('[name=lprice]').validate({ event: ...
- 【BLE】CC2541之自己定义按键
本篇博文最后改动时间:2017年01月06日,11:06. 一.简单介绍 本文以SimpleBLEPeripheral为例.介绍怎样将普通IO口(P12)自己定义为按键. 注:本文加入按键方法不与协议 ...