传送门:

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

ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2224

大意:给你一堆本金,还有投资方案获得的利润。让你进行合理投资,要求若干年后获利最大。

完全背包问题。背包容量就是money,要尽量装满(不是风险投资哇,投资出去必获利)

开始天真的开了400多w(100万*1.1^40)的数组,直接TLE掉。

看了discuss里,因为给的利润为1000的整数倍,故可以将其/1000,那么背包大小也小了,时间上63ms zoj上40ms

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN=45260+10;
int dp[MAXN];
int cost[12],repay[12];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int money,year,len;
scanf("%d%d%d",&money,&year,&len);
for(int i=1;i<=len;i++)
{
scanf("%d%d",&cost[i],&repay[i]);
cost[i]/=1000;
} for(int y=1;y<=year;y++)
{
int temp=money/1000;
for(int i=1;i<=len;i++)
{
for(int j=cost[i];j <= temp ;j++)
{
dp[j]=max(dp[j], dp[j - cost[i]]+repay[i]);
}
}
money=money+dp[temp];
}
printf("%d\n",money);
memset(dp,0,sizeof(dp));
}
}

poj 2063 Investment ( zoj 2224 Investment ) 完全背包的更多相关文章

  1. POJ 1384 Piggy-Bank (ZOJ 2014 Piggy-Bank) 完全背包

    POJ :http://poj.org/problem?id=1384 ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode ...

  2. POJ 2063 Investment (完全背包)

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

  3. 专题复习--背包问题+例题(HDU 2602 、POJ 2063、 POJ 1787、 UVA 674 、UVA 147)

    *注 虽然没什么人看我的博客但我还是要认认真真写给自己看 背包问题应用场景给定 n 种物品和一个背包.物品 i 的重量是 w i ,其价值为 v i ,背包的容量为C.应该如何选择装入背包中的物品,使 ...

  4. POJ 2240 Arbitrage / ZOJ 1092 Arbitrage / HDU 1217 Arbitrage / SPOJ Arbitrage(图论,环)

    POJ 2240 Arbitrage / ZOJ 1092 Arbitrage / HDU 1217 Arbitrage / SPOJ Arbitrage(图论,环) Description Arbi ...

  5. POJ 2063 Investment 完全背包

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

  6. POJ 2063 Investment 滚动数组+完全背包

    题目链接: http://poj.org/problem?id=2063 题意: 你现在有现金m元,你要做n年的存款投资,给你k种投资方式,每种需要现金vi元,能获得xi元的理论,一年到期后你要利用拿 ...

  7. [POJ 2063] Investment (动态规划)

    题目链接:http://poj.org/problem?id=2063 题意:银行每年提供d种债券,每种债券需要付出p[i]块钱,然后一年的收入是v[i],到期后我们把本金+收入取出来作为下一年度本金 ...

  8. poj 2063 Investment

    题意:给定一个初始资金capital,然后给定d种投资方案,每种投资方案中有投资额value[i](是1000的倍数)和利息interest[i],每年的投资就可以拿到全部利息,然后累加起来继续投资利 ...

  9. poj 2063 Investmen 完全背包

    这个题的想法不难,两个点: 1 是完全背包 2 是考虑/1000,降低复杂度   但是提交的时候反复的wa,最后找问题原来是dp开小了,可是dp本来开1005,后来开到100030过了.哎,如果没有时 ...

随机推荐

  1. Unity 3D 开发 —— 脚本编程

    Unity 相关资源 Unity 官网 :http://www.unity3D.com Unity 论坛 : http://forum.unity3d.com/forum.php Unity 问答 : ...

  2. hadoop安装报错

    1.Hadoop安装完后,启动时报Error: JAVA_HOME is not set and could not be found. 解决办法: 修改/etc/hadoop/hadoop-env. ...

  3. Linux MTD 子系统

    一.MTD子系统概述 MTD(Memory Technology Device, 内存技术设备)是用于访问memory 设备 (ROM.FLASH)的Linux子系统. 主要目的是为了使新的memor ...

  4. Linux "零拷贝" sendfile函数中文说明及实际操作分析

    Sendfile函数说明 #include ssize_t sendfile(int out_fd, int in_fd, off_t *offset, size_t count); sendfile ...

  5. 怎样利用ash监控会话

    ash是很有效的监控工具之中的一个.1秒抓一次 select max(sample_time)over(),min(sample_time)over() from dba_hist_active_se ...

  6. Android学习笔记进阶十三获得本地全部照片

    这是Intent的一个用法. 在ActivityAction里面有一个“ACTION_GET_CONTENT”字符串常量,该常量让用户选择特定类型的数据. intent.setType("i ...

  7. 11.Bean2Document-BEAN转document

    1. package com.glodon.gspm.adapter.plugin.common; import com.glodon.cloudt.tenancy.context.TenantCon ...

  8. Filebeat之input和output(包含Elasticsearch Output 、Logstash Output、 Redis Output、 File Output和 Console Output)

    前提博客 https://i.cnblogs.com/posts?categoryid=972313 Filebeat啊,根据input来监控数据,根据output来使用数据!!! Filebeat的 ...

  9. css实现一个缺口小三角

    .square{ width:; height:; margin:0 auto; border:6px solid transparent; border-bottom: 6px solid red; ...

  10. 数据库SQL Server2012笔记(七)——java 程序操作sql server

    1.crud(增删改查)介绍:create/retrieve/update/delete 2.JDBC介绍 1)JDBC(java database connectivity,java数据库连接) 2 ...