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> ...
随机推荐
- java 入门 第二季4
1. 多态 继承是多态的实现基础 引用的多态 父类的引用可以指向本类的对象 父类的引用可以指向子类的对象 方法的多态 创建本类对象时,调用本类方法 2种是调用子类的方法或继承的方法 子类中添加独有的方 ...
- iOS AES加密解密实现方法
使用方法 先导入头文件 #import "NSData+AES.h" //AES测试 //用来密钥 NSString *key = "; //用来发送的原始数据 NSSt ...
- JS 保留两位小数问题收集
1.使用四舍五入的方法,保留小数点后的两位小数: toFixed里面的参数表示保留的小数的位数,范围是0-20,超过20位就会报错了 <script> var num=22.127456; ...
- html与js传json值给php
//一段js代码 var data = {}, act = [], list = []; $('.set').find('input, textarea').each(function() { act ...
- 用Python套接字创建HTTP客户与服务器程序
最近在学习python,网络编程中,python寥寥几句,就可以创建一个服务端和客户端程序: 服务端: import sockets = socket.socket()host = socket.ge ...
- Stanford大学机器学习公开课(三):局部加权回归、最小二乘的概率解释、逻辑回归、感知器算法
(一)局部加权回归 通常情况下的线性拟合不能很好地预测所有的值,因为它容易导致欠拟合(under fitting).如下图的左图.而多项式拟合能拟合所有数据,但是在预测新样本的时候又会变得很糟糕,因为 ...
- 使用Gson送解析Json格式
Java bean: package com.jingle.a; public class Person { public String name; public int age; public Pe ...
- poj2236(并查集)
题目链接: http://poj.org/problem?id=2236 题意: 有n台计算机, 已知每台计算机的坐标, 初始时所有计算机都是坏的, 然后修复其中一些计算机, 已修复的计算机距离不超过 ...
- Xcodeproject详解
前言 在 iOS 开发过程中,我们经常会在 Xcode 里面做一些配置,比如添加系统库.第三方库,修改证书配置文件,修改编译属性等等. 在这个过程里面,一般大家仅仅只是根据经验来配置这些,并没有比较清 ...
- NYOJ题目113字符串替换
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAr4AAAHvCAIAAAA930vtAAAgAElEQVR4nO3dPVLjysIG4G8T5CyE2A ...