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. 使用kendynet编写网关服务

    网游服务器大多提供了网关服务,用于作为用户和内部服务器组之间通信代理.网关服务一方面将用户消息从客户端分发到正确的内部服务器. 另一方面将来自内部服务器的数据包转发给客户端.一般对于网关应用来说,压力 ...

  2. 如何在浏览器中简单模拟微信浏览器(仅限于通过User Agent进行判断的页面)

    模拟微信浏览器: .打开360极速 .F12开发者工具 .开发者模式左上方有一个手机样子的图标 点击进入 设备模式‘ .将UA选项中的字符串替换成: Mozilla/ 备注: 替换的字符串是微信浏览器 ...

  3. 剑指offer——35复杂链表的复制

    这题很是巧妙. 突破了常规思维. 竟然可以把传入进来的链表和复制的链表链在一起.然后再算出slibling指针.最后在分离. 直接把空间复杂度变为O(1)了. 很巧妙,很实用. 题目: 请实现函数Co ...

  4. Github for Windows 登录时报代理问题?

    Github for Windows 登录时报如下错误: 不要被它的提示信息误导了. 登录失败,跟代理半毛钱关系都没有. 是 .net framework 组件 的问题. 更新下 .net frame ...

  5. bs-loading

    根据bootstrap的modal来显示loading动效. 核心内容: 1.图片转base64方法: // 图片压缩-start function run(input_file,get_data){ ...

  6. LeetCode 33 Search in Rotated Sorted Array(循环有序数组中进行查找操作)

    题目链接 :https://leetcode.com/problems/search-in-rotated-sorted-array/?tab=Description   Problem :当前的数组 ...

  7. spring boot 单元测试,如何使用profile

    一.问题概述 spring boot项目.单元测试的时候,我发现,总是会使用application.properties的内容,而该文件里,一般是我的开发时候的配置. 比如上图中,dev是开发配置,p ...

  8. jenkins或ansible启动应用不成功日志又不报错

    碰到ansible无法起停tomcat的时候,有3个点需要关注 1.环境变量,在startup.sh中添加source /etc/profile 2.后台运行,加上nohup...& 3.单独 ...

  9. jmeter中Implementation中几个选项的区别

    在jmeter发送http请求时,Implementation下拉框中有几个选项,如下: 那到底有什么区别呢?发送http请求改用哪种方法呢.百度后查之,没答案.我们还是看官方文档吧.官方文档解释如下 ...

  10. linux启动程序和关闭程序脚本

    关闭脚本: #!/bin/bash source /etc/profile log() { echo `date +[%Y-%m-%d" "%H:%M:%S]` $1 } log ...