poj 2063 Investmen 完全背包
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 10087 | Accepted: 3539 |
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
Sample Input
1
10000 4
2
4000 400
3000 250
Sample Output
14050
Source
#include<iostream>
#include<stdio.h>
#include<cstring>
using namespace std;
const int maxx = ;
//long long dp[maxx][maxx];
int dp[];
int bag;
int w[maxx],v[maxx];
int kind;
int year;
int get()
{
memset(dp,,sizeof(dp));
/* for(int i=1;i<=kind;i++)
{
for(int j=0;j<=bag;j++)
{
for(int k=0;k*w[i]<=j;k++)
{
dp[i][j]=max(dp[i][j],dp[i-1][j-w[i]*k]+v[i]*k);
} }
}
bag=dp[kind][bag];
return bag;*/
for(int i=;i<=kind;i++)
{
for(int j=w[i];j<=bag;j++)
{
dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
}
}
return dp[bag];
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int ans=;
scanf("%d%d",&bag,&year);
scanf("%d",&kind);
ans=bag;
bag/=;
for(int i=;i<=kind;i++)
{
scanf("%d%d",&w[i],&v[i]);
w[i]/=;
}
for(int k=;k<year;k++)
{
ans+=get();
bag=(ans/); }
printf("%d\n",ans);
}
return ;
}
poj 2063 Investmen 完全背包的更多相关文章
- POJ 2063 Investment 完全背包
题目链接:http://poj.org/problem?id=2063 今天果然是卡题的一天.白天被hdu那道01背包的变形卡到现在还没想通就不说了,然后晚上又被这道有个不大也不小的坑的完全背包卡了好 ...
- POJ 2063 Investment (完全背包)
A - Investment Time Limit:1000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64u Subm ...
- 专题复习--背包问题+例题(HDU 2602 、POJ 2063、 POJ 1787、 UVA 674 、UVA 147)
*注 虽然没什么人看我的博客但我还是要认认真真写给自己看 背包问题应用场景给定 n 种物品和一个背包.物品 i 的重量是 w i ,其价值为 v i ,背包的容量为C.应该如何选择装入背包中的物品,使 ...
- 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完全背包
题意:给出总资金和投资年份 ,n个股票 给出股票价格和其一年的利润.问如何选择能获得最大利润. 思路:股票可以重复选择,完全背包问题,完全背包也是从01背包衍生而行的,其主要区别在于中间那层循环的次序 ...
- POJ 1155 (树形DP+背包+优化)
题目链接: http://poj.org/problem?id=1155 题目大意:电视台转播节目.对于每个根,其子结点可能是用户,也可能是中转站.但是用户肯定是叶子结点.传到中转站或是用户都要花钱, ...
- [POJ 2063] Investment (动态规划)
题目链接:http://poj.org/problem?id=2063 题意:银行每年提供d种债券,每种债券需要付出p[i]块钱,然后一年的收入是v[i],到期后我们把本金+收入取出来作为下一年度本金 ...
- poj 3211 Washing Clothes(背包)
很不错的01背包!!! 不过有点疑问!!!(注释) #include <algorithm> #include<stdio.h> #include<string.h> ...
随机推荐
- CAD2010中文版安装问题记录
CAD2010中文版安装到简体中文语言包的时候提示[错误1606无法访问网络位置setup],直接打开cad2010 提示 [adui18res.dll not found]: 首先,进入注册表(re ...
- Greedy:Cow Acrobats(POJ 3045)
牛杂技团 题目大意:一群牛想逃跑,他们想通过搭牛梯来通过,现在定义risk(注意可是负的)为当前牛上面的牛的总重量-当前牛的strength,问应该怎么排列才能使risk最小? 说实话这道题我一开始给 ...
- VC++ 判断当前系统为32位还是64位
尝试了在VC++环境下判断系统为32位还是64位的方法,亲测有效!提供的函数如下 BOOL IsWow64() { typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) ...
- OKhttp基本使用介绍
MainActivity.class package com.example.administrator.okhttp3; import android.support.v7.app.AppCompa ...
- 【XLL 框架库函数】 debugPrintf
通过调用 Windows SDK 函数 OutputDebugStringA 在激活的调试器中输出字符串信息.如果应用程序没有调试器,那么系统调试器就会显示字符串.如果这两种调试器都没使用的话,deb ...
- yii 多模板
main.php: //替换所有模板 //加载文件名为first的模板 // 'theme'=>'theme1', 'components'=>array( ...
- CentOS7下Firewall防火墙配置用法详解
官方文档地址: https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Security_Guide ...
- route netstat -rn
-n :不要使用通讯协定或主机名称,直接使用ip或port number; -ee:使用更详细的资讯来显示 [root@NB data]# route -nee Kernel IP routing t ...
- Linux LVM全面实践
1.磁盘分区 [root@ol6-121-rac1 ~]# fdisk /dev/sdb Device contains neither a valid DOS partition table, no ...
- Excel数据挖掘插件
Excel是大家非常熟悉的表格工具,借助它可以实现日程工作中最原始的数据处理的基本的功能,此外通过 SQL Server插件的支持,我们也可以在Excel中实现数据挖掘的功能. 此篇将先介绍Excel ...