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 题目大意:电视台转播节目.对于每个根,其子结点可能是用户,也可能是中转站.但是用户肯定是叶子结点.传到中转站或是用户都要花钱, ...
随机推荐
- MySQL监控工具——innotop
MySQL监控工具--innotop innotop是一个mysql数据库实时监控工具,其功能强大,信息种类繁多,很能体现数据库的状态. 它实际上是一个perl脚本,整合show status/sho ...
- 从零开始搭建GitHub个人博客--第一步
最近一段时间工作不是很忙,便开始着手整理博客并梳理自己的简历 可是,打开cnblog后第一眼我便开始了纠结~ 原起: 一直在cnblog写博客,看博客,突然发现这种在线纯文档记录的方式俨然跟不上时代的 ...
- PropertyGrid—属性类别排序
属性默认按照字母顺序排序,有时,我们想要按自定义的顺序排序 这个工具类可以把每个属性类别里的属性排序,但是不能把属性类别排序. 为属性类添加属性:[TypeConverter(typeof(Prope ...
- C#控件之ListView
1.添加一行 listView1.Items.Add(new ListViewItem(new string[] {str1, str2, str3 })); 2.鼠标悬停在listview某项时弹出 ...
- linux 文件删除恢复extundelete
首先要把删除文件所有磁盘分区卸载掉 然后安装yum install -y extundelete *2fs* extundelete /dev/sdb1 --inode #查看sdb1分区下删除的文件 ...
- vuex mapGetters
1.vuex 配置 //vuex的配置 //注意Store是大写 const store = new Vuex.Store({ //数据保存 state: { show: false, count: ...
- LeetCode Subsets I& II——递归
I Given a set of distinct integers, S, return all possible subsets. Note: Elements in a subset must ...
- JS图片预加载插件
在开发H5项目中有时候会遇到要加载大量图片的情况,利用预加载技术可以提高用户浏览时的体验. 1)概念:懒加载也叫延迟加载:JS图片延迟加载,延迟加载图片或符合某些条件时才加载某些图片.预加载:提前加载 ...
- javascript关闭弹出窗体时刷新父窗体和居中显示弹出窗
居中显示用到了moveTO()方法: 关闭弹出窗时刷新父窗体用到了window.opener方法: 父窗体代码例如以下: <%@ Page Language="C#" Aut ...
- Spring Boot 从入门到实战汇总
之前写过几篇spring boot入门到实战的博文,因为某些原因没能继续. 框架更新迭代很快,之前还是基于1.x,现在2.x都出来很久了.还是希望能从基于该框架项目开发的整体有一个比较系统的梳理,于是 ...