这个题的想法不难,两个点:
1 是完全背包
2 是考虑/1000,降低复杂度
但是提交的时候反复的wa,最后找问题原来是dp开小了,可是dp本来开1005,后来开到100030过了。哎,如果没有时间计算
dp的长度的话,就往大了开,血的教训。
Investment
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 10087   Accepted: 3539

Description

John never knew he had a grand-uncle, until he received the notary's letter. He learned that his late grand-uncle had gathered a lot of money, somewhere in South-America, and that John was the only inheritor. 
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 contains a single positive integer N which is the number of test cases. The test cases follow. 
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

For each test case, output – on a separate line – the capital at the 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

Source

Northwestern Europe 2004

#include<iostream>
#include<stdio.h>
#include<cstring>
using namespace std;
const int maxx = 105;
//long long dp[maxx][maxx];
int  dp[100030];
int  bag;
int  w[maxx],v[maxx];
int kind;
int year;
int  get()
{memset(dp,0,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=1;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=0;scanf("%d%d",&bag,&year);scanf("%d",&kind);ans=bag;bag/=1000;for(int i=1;i<=kind;i++){scanf("%d%d",&w[i],&v[i]);w[i]/=1000;}for(int k=0;k<year;k++){ans+=get();bag=(ans/1000);}printf("%d\n",ans);}return 0;
}

View Code

转载于:https://www.cnblogs.com/superxuezhazha/p/5746807.html

poj 2063 Investmen 完全背包相关推荐

  1. poj 2063 Investment(01背包变形)

    http://poj.org/gotoproblem?pid=2063 (1)上限 m 一直上升的 n 次01背包问题,比一般的01背包多了一重循环: (2)本题出现了各种错误:1)刚开始,没注意 m ...

  2. poj 2063完全背包

    题意:给出总资金和投资年份 ,n个股票 给出股票价格和其一年的利润.问如何选择能获得最大利润. 思路:股票可以重复选择,完全背包问题,完全背包也是从01背包衍生而行的,其主要区别在于中间那层循环的次序 ...

  3. Piggy-Bank POJ - 1384(完全背包+背包放满)

    题意: 给出一个存钱罐的重量和没存钱之前存钱罐的重量,然后给出几种硬币的重量和币值,计算存钱罐里至少有多少钱. 题目: Before ACM can do anything, a budget mus ...

  4. POJ - 2392 朴素多重背包 + 贪心 WA与AC代码细节分析

    我们先来看下普通的朴素多重背包(拆成01背包求解) n种物品,背包大小w,每种物品重量 wi,价值 vi,个数 ci dp[j] 表示 大小为 j 的背包含有的最大价值,即 物品重量和 小于等于 j ...

  5. poj 2923(状态压缩+背包)

    比较巧妙的一道题目,拿到题目就想用暴力直接搜索,仔细分析了下发现复杂度达到了2^n*n! ,明显不行,于是只好往背包上想. 于是又想二分找次数判断可行的方法,但是发现复杂度10^8还是很悬... 然后 ...

  6. DP专题 4 | 骨头收集爱好者 - POJ 1458( 0-1背包)

    背包问题是DP里面变化比较多的问题,可以参考网上的<背包9讲>,另外还是阅读<算竞入门>和<算竞进阶>,讲的最全的肯定是背包9讲,基本上把所有变形都讲了一遍,但是把 ...

  7. Coins POJ - 1742(多重背包+是否装满问题)

    题意: 给定n种面值的硬币面值分别为WiW_{i}Wi​个数为CiC_{i}Ci​,问用这些硬币可以组成1~m之间的多少面值. 题目: People in Silverland use coins.T ...

  8. poj 1837 blance (01背包)

    题意 : 有一个特俗的天平 c 个指定的位置 g个给定重量的砝码 问用上所有砝码 使天平平衡的方案有几种 思路: dp[i][j+c[k]*g[i]]+=dp[i-1][j]; #include< ...

  9. 多重背包模板 C++

    多重背包模板 多重背包: 有N种物品和一个容量为V的背包.第i种物品最多有numi件可用. 每件物品的重量是wi,价值是vi. 求解将哪些物品装入背包可使这些物品的重量总和不超过背包容量,且价值总和最 ...

最新文章

  1. 用零知识证明解决投票安全
  2. Unity制作的 安卓和Ios程序如何退出
  3. [codevs 1249] 多边形的面积
  4. 进程间的通信方式:简介
  5. GetWindowRect() 和 GetClientRect() 的区别
  6. 博客园添加鼠标粒子吸附特效
  7. [Ajax] jQuery中的Ajax -- 01-jQuery中的Ajax
  8. java response文件流下载,后缀名称设置
  9. fork()成为负担,需要淘汰 | 极客头条
  10. .NET基础知识(一)
  11. 同济版《线性代数》再遭口诛笔伐,网友:它真的不太行
  12. 17个机器学习的常用算法
  13. js获取屏幕高度、宽度
  14. php企业微信获取userid,企业微信端项目登陆、获取用户信息流程等
  15. c语言rank函数使用实例,rank函数实例(1)
  16. css3图片放大溢出,用canvas调整图像大小 - css溢出问题
  17. 【数据爬取和数据分析】Q房网深圳二手房源分析
  18. 【财富空间】陈春花:向内打破,为成长赋能;面对全球市场,要有全球化思维、本土化行动
  19. python中怎么撤回_python如何查看微信消息撤回
  20. EXCEL基础操作:隐藏,冻结,查找(搜索),锁定,保护

热门文章

  1. python设置window系统ip
  2. 世界上任何一件事的五个模块
  3. [转]设计模式六大原则[1]:单一职责原则
  4. (十)java多线程之CountDownLatch
  5. 数据结构(动态树):[国家集训队2012]tree(伍一鸣)
  6. Objective-C Runtime 运行时与类的内部构造
  7. 【转载】java中Date与String的相互转化
  8. Nest,很酷的东西
  9. .NET中的异步编程(一)-为什么需要异步
  10. [Vue.js]实战 -- 电商项目(二)