http://poj.org/problem?id=2063

首先总结一下:总的来说通过这题我深深感觉到了自己的不足,比赛时思维很受限,。。。面对超时,没有想到好的解决方案。

题意:给出初始资金,还有年数,然后给出每个物品的购买价格与每年获得的利益,要求在给出的年份后所能得到的最大本利之和。

思路:因为每种物品可以多次购买,可以看做是完全背包的题目,但是要注意的是,由于本金可能会很大,所以我们要对背包的大小进行压缩,(否则超时超内存)值得注意的是,题目已经说了本金与物品的购买价格都是1000的倍数,所以我们可以将他们都除以1000来进行压缩,然后就是一道完全背包模板题了。

解决方案:完全背包问题,因为每种股票可以无限投资,而问n年之后的最大收益,我们将每一年的最大收益计算,将前i-1年的现有收益作为现在投资金额再次对第i年进行投资。

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
int dp[];
int main()
{
int T,V,time,d,VV;//V是背包的容积,w[i]是物品的体积
int w[],v[];
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&V,&time);
scanf("%d",&d);
VV=V;
for(int i=;i<=d;i++)
{
scanf("%d%d",&w[i],&v[i]);
w[i]=w[i]/;//因为证券都是1000的倍数
}
for(int i=;i<=time;i++)
{
V=VV/;//因为证券都是1000的倍数,钱数不满整千绝对不能买,所以完全可以/1000
for(int j=;j<=V;j++)
dp[j]=;
for(int j=;j<=d;j++)
{
for(int k=w[j];k<=V;k++)
{
if(dp[k]<dp[k-w[j]]+v[j])
{
dp[k]=dp[k-w[j]]+v[j];
}
}
}
VV=VV+dp[V];//钱数累加
}
printf("%d\n",VV);
}
return ;
}

poj2063 Investment的更多相关文章

  1. POJ2063 Investment 【全然背包】

    Investment Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 8019   Accepted: 2747 Descri ...

  2. poj2063 Investment(多次完全背包)

    http://poj.org/problem?id=2063 多次完全背包~ #include <stdio.h> #include <string.h> #define MA ...

  3. poj分类解题报告索引

    图论 图论解题报告索引 DFS poj1321 - 棋盘问题 poj1416 - Shredding Company poj2676 - Sudoku poj2488 - A Knight's Jou ...

  4. HDU1963 && POJ2063:Investment(完全背包)

    Problem Description John never knew he had a grand-uncle, until he received the notary’s letter. He ...

  5. Case Studies: Retail and Investment Banks Use of Social Media

    The past couple of months have seen an increased acknowledgement of the role social media has to pla ...

  6. [HDU 1963] Investment

    Investment Time Limit:10000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu   Descrip ...

  7. POJ 2063 Investment (完全背包)

    A - Investment Time Limit:1000MS     Memory Limit:30000KB     64bit IO Format:%I64d & %I64u Subm ...

  8. A - Investment

    A - Investment John never knew he had a grand-uncle, until he received the notary's letter. He learn ...

  9. POJ 2063 Investment 完全背包

    题目链接:http://poj.org/problem?id=2063 今天果然是卡题的一天.白天被hdu那道01背包的变形卡到现在还没想通就不说了,然后晚上又被这道有个不大也不小的坑的完全背包卡了好 ...

随机推荐

  1. 【cs229-Lecture3】Logistic回归

    参考: http://www.itongji.cn/article/12112cH013.html http://blog.csdn.net/zouxy09/article/details/20319 ...

  2. springbatch---->springbatch的使用(一)

    这里我们通过一个简单的实例来对springbatch做一个入门的体会.刚刚好,看见你幸福的样子,于是幸福着你的幸福. springbatch的入门案例 简单项目的结构如下: 一.引入maven的spr ...

  3. springbatch---->springbatch的使用(二)

    这里我们对springbatch做一个比较深入的学习例子,解压文件,读取文件内容过滤写入到数据库中.如果你掉进了黑暗里,你能做的,不过是静心等待,直到你的双眼适应黑暗. springbatch的使用案 ...

  4. Linux(Ubuntu)下如何解压 .zip 文件

    安装解压缩软件 使用如下命令安装: sudo apt-get install p7zip-full 7zip,估计会比较熟悉. p7zip,是什么? 听说是 7zip 的 shell 封装. 解压 使 ...

  5. Linux命令 uname:查看系统与内核相关信息

    zh@zh:~$uname --help zh@zh:~$uname -a //所有系统相关的信息

  6. 题目1099:后缀子串排序(qsort函数自定义cmp函数)

    题目链接:http://ac.jobdu.com/problem.php?pid=1099 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus 参考代码: ...

  7. sencha touch list 批量选择扩展(2013-7-29)

    扩展js代码 /* *list多选扩展 */ Ext.define('ux.SimpleList', { alternateClassName: 'simpleList', extend: 'Ext. ...

  8. explain 和 desc 详解

    MySQL性能分析 1.使用explain语句去查看分析结果 如explain select * from test1 where id=1;会出现:id  selecttype  table  ty ...

  9. 分布式文件系统FastDFS架构剖析

    ps.本文来自于网络 一.什么是FastDfs FastDFS是一个开源的轻量级分布式文件系统,它对文件进行管理,功能包括:文件存储.文件同步.文件访问(文件上传.文件下载)等,解决了大容量存储和负载 ...

  10. Java虚拟机四 常用Java虚拟机参数

    主要涉及的知识点: 1.跟踪Java虚拟机的垃圾回收和类加载等信息: 2.配置Java虚拟机的堆空间: 3.配置永久区和Java栈. 4.学习虚拟机的服务器和客户端模式. 1.1 跟踪垃圾回收 Jav ...