Investment(完全背包)
个人心得:炸了炸了,这背包什么的脑阔痛。
完全背包什么鬼咯,状态正向转移与01背包正好相反。

二维数组的状态转移。

一维数组的优化,注意正向覆盖。
本题中的思想
for(int y=;y<=year;y++){
int s=cash/;
for(int i=;i<=n;i++){
for(int j=bond[i];j<=s;j++){
dp[j]=max(dp[j],dp[j-bond[i]]+gain[i]);
}
}
cash+=dp[s];
}
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
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
const int money=;
const int MAXN=;
int bond[],gain[];
int dp[];
int main(){
int t;
cin>>t;
while(t--){
int cash,year,n;
cin>>cash>>year>>n;
memset(dp,,sizeof(dp));
for(int i=;i<=n;i++)
{
cin>>bond[i]>>gain[i];
bond[i]/=money;
}
int k,ans;
for(int y=;y<=year;y++){
int s=cash/;
for(int i=;i<=n;i++){
for(int j=bond[i];j<=s;j++){
dp[j]=max(dp[j],dp[j-bond[i]]+gain[i]);
}
}
cash+=dp[s];
}
cout<<cash<<endl;
}
return ;
}
Investment(完全背包)的更多相关文章
- POJ 2063 Investment 完全背包
题目链接:http://poj.org/problem?id=2063 今天果然是卡题的一天.白天被hdu那道01背包的变形卡到现在还没想通就不说了,然后晚上又被这道有个不大也不小的坑的完全背包卡了好 ...
- hdu 1963 Investment 多重背包
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1963 //多重背包 #include <cstdio> #include <cstr ...
- HDU1963 && POJ2063:Investment(完全背包)
Problem Description John never knew he had a grand-uncle, until he received the notary’s letter. He ...
- poj 2063 Investment ( zoj 2224 Investment ) 完全背包
传送门: POJ:http://poj.org/problem?id=2063 ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problem ...
- poj分类解题报告索引
图论 图论解题报告索引 DFS poj1321 - 棋盘问题 poj1416 - Shredding Company poj2676 - Sudoku poj2488 - A Knight's Jou ...
- POJ2063 Investment 【全然背包】
Investment Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 8019 Accepted: 2747 Descri ...
- poj2063 Investment(多次完全背包)
http://poj.org/problem?id=2063 多次完全背包~ #include <stdio.h> #include <string.h> #define MA ...
- POJ 2063 Investment 滚动数组+完全背包
题目链接: http://poj.org/problem?id=2063 题意: 你现在有现金m元,你要做n年的存款投资,给你k种投资方式,每种需要现金vi元,能获得xi元的理论,一年到期后你要利用拿 ...
- POJ 2063 Investment (完全背包)
A - Investment Time Limit:1000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64u Subm ...
随机推荐
- rails 增删改查
class InvoicesController < ApplicationController def index @invoices = Invoice.all end def show @ ...
- loadrunder之脚本篇——集合点设置
1 作用 通过让多用户在同一时间点上进行并发操作来测试系统的并发处理的能力 2 实现 通过集合点函数来实现. 注意:集合点经常和事务结合起来使用.集合点只能插入到Action部分,vuser_in ...
- arm64的适配问题,这次真醉了
写过tableView的童鞋都知道,有必须的两个代理方法要实现,还有几个选择实现的. 必须实现的代理方法: ~设置行数 - (NSInteger)tableView:(UITableView *)ta ...
- 2018.7.12训练赛 -K
水题 判断素数 因为范围是到16位,所以可以用long long存储 然后判断是否为素数就ok了. 但我提交之后显示10个测试样例通过了9个.......原因是下面标红的部分. 埃氏筛法:若a是合数, ...
- XXL-Job分布式任务调度
分布式情况下定时任务会出现哪些问题? 分布式集群的情况下,怎么保证定时任务不被重复执行 分布式定时任务解决方案 ①使用zookeeper实现分布式锁 缺点(需要创建临时节点.和事件通知不易于扩展) ② ...
- 【bzoj2819】Nim(dfs序+树状数组/线段树)
题目传送门:https://www.lydsy.com/JudgeOnline/problem.php?id=2819 首先根据SG定理,可得若每堆石子数量的异或值为0,则后手必胜,反之先手必胜.于是 ...
- WEB开发中常见漏洞
1.sql注入 SQL注入在黑客领域是一种非常常见的攻击手段,大家应该都听说过很多数据泄漏的案例,其中大部分都是采用SQL注入来获取数据的. SQL注入一般是前端向后台提交数据的时候,在数据中加入SQ ...
- [转载]Spring配置文件详解一:
原文地址:与base-package="com.xx">Spring配置文件详解一:<context:annotation-config/>与<contex ...
- windows系统JDK的安装及环境配置
本文转载至:http://blog.csdn.net/sweetburden2011/article/details/8881181 一:JDK的安装 1. 首先上甲骨文公司的官方网站下载JDK的 ...
- C++的转换函数
听侯捷老师的讲课笔记: 所谓转换函数指的是类型之间的转换,比如把自定义的类类型转换成内建类型(比如double),后者向相反的方向转. 直接上代码: 头文件conversion_function.h: ...