poj2063 Investment
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的更多相关文章
- 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分类解题报告索引
图论 图论解题报告索引 DFS poj1321 - 棋盘问题 poj1416 - Shredding Company poj2676 - Sudoku poj2488 - A Knight's Jou ...
- HDU1963 && POJ2063:Investment(完全背包)
Problem Description John never knew he had a grand-uncle, until he received the notary’s letter. He ...
- 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 ...
- [HDU 1963] Investment
Investment Time Limit:10000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Descrip ...
- POJ 2063 Investment (完全背包)
A - Investment Time Limit:1000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64u Subm ...
- A - Investment
A - Investment John never knew he had a grand-uncle, until he received the notary's letter. He learn ...
- POJ 2063 Investment 完全背包
题目链接:http://poj.org/problem?id=2063 今天果然是卡题的一天.白天被hdu那道01背包的变形卡到现在还没想通就不说了,然后晚上又被这道有个不大也不小的坑的完全背包卡了好 ...
随机推荐
- URL域名获取
http://"是协议名 "www.test.com"是域名 "是端口号 "aaa"是站点名 "bbb.aspx"是页面 ...
- sql server性能查询,连接数
1)使用以下查询语句: select * from sysprocesses where dbid in (select dbid from sysdatabases where name='My ...
- 本版本延续MVC中的统一验证机制~续的这篇文章,本篇主要是对验证基类的扩展和改善(转)
本版本延续MVC中的统一验证机制~续的这篇文章,本篇主要是对验证基类的扩展和改善 namespace Web.Mvc.Extensions { #region 验证基类 /// <summary ...
- C# 中文日期 周几
//该语句显示的为英文格式 DateTime.Now.DayOfWeek.ToString(); //显示中文格式星期几 "星期" + DateTime.Now.ToString( ...
- php strpos(), stripos(),strrpos(), strripos()的区别
strpos(), 左边开始,字符出现第一个位置,区分大小写: stripos(),不区分大小写: strrpos(), 左边开始,字符出现,最后一个位置,区分大小写: strripos()不区分大小 ...
- tars环境部署
author: headsen chen date: 2018-10-18 12:35:40 注意:依据Git上的tars搭建步骤整理而来 参考: https://max.book118.com/h ...
- C# IO流的操作(一)
C# IO流的操作非常重要,我们读写文件都会使用到这个技术,这里先演示一个文件内容复制的例子,简要说明C#中的IO操作. namespace ConsoleApplication1 { class P ...
- 解决Android 5.0中出现的警告:Service Intent must be explicit
extends:http://www.eoeandroid.com/thread-568853-1-1.html 本帖最后由 469874851 于 2015-3-11 18:15 编辑 有些时候我们 ...
- Unity3D笔记 英保通三 脚本编写 、物体间通信
一.脚本编写 1.1.同一类型的方法JS和C#的书写方式却不一样主要还是语法,在工程中创建一个Cube 分别把JSTest.js和CSharp.cs 添加到Cube中 JSTest.js #pragm ...
- APM飞控的使用心得
硬件资源:APM,F450四轴机架,大疆电调和电机,富斯i6控和接收机. 刚开始的步骤都是大同小异,首先可以按照这个链接上面的步骤一步步的执行:http://tieba.baidu.com/p/297 ...