POJ 2063 Investment

13 篇文章 0 订阅


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

题意:一个人开始有M$钱用来投资,D种债券,每种费用Ci(且Ci有:The value of a bond is always a multiple of $1 000),年底可获利Vi。第二年又可用初始的钱+盈利的钱去投资,一共投资Y年。

分析:完全背包。由于初始的钱很大(100W),所以直接做会TLE。(看到题我想都没想就直接上去写了个完全背包,结果TLE。。。)后来发现题目的这句话The value of a bond is always a multiple of $1 000。 才想到要把初始的钱数和每种债券的费用除以1000,这样时间复杂度就可以接受了。可提交之后还是TLE。后来把初始化数组的memset改为for循环之后60MS+AC。


Code:

#include<iostream>
#include<cstring>
#include<cstdio>
#define Max(a,b) ((a)>(b)?(a):(b))
using namespace std;

int f[100010];
int cost[15],val[15];
int year,d,mon;

int main()
{
    int cas;
    scanf("%d",&cas);
    while(cas--){
        scanf("%d %d %d",&mon,&year,&d);
        for(int i=1;i<=d;i++){
            scanf("%d %d",&cost[i],&val[i]);
            cost[i]/=1000;
        }
        for(int y=1;y<=year;y++){
            int V=mon/1000;                 //这里不必考虑精度问题,因为小于1000的部分买不到任何债券
            for(int i=0;i<=V;i++) f[i]=0;
            for(int i=1;i<=d;i++){
                for(int j=cost[i];j<=V;j++){
                    f[j]=Max(f[j],f[j-cost[i]]+val[i]);
                }
            }
            mon+=f[V];
        }
        printf("%d\n",mon);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值