您的位置:首页 > 其它

POJ 2063 Investment

2013-08-01 19:12 323 查看
[b]Investment[/b]

TimeLimit:1000MSMemoryLimit:30000K
TotalSubmissions:6836Accepted:2367
Description

Johnneverknewhehadagrand-uncle,untilhereceivedthenotary'sletter.Helearnedthathislategrand-unclehadgatheredalotofmoney,somewhereinSouth-America,andthatJohnwastheonlyinheritor.
Johndidnotneedthatmuchmoneyforthemoment.Butherealizedthatitwouldbeagoodideatostorethiscapitalinasafeplace,andhaveitgrowuntilhedecidedtoretire.Thebankconvincedhimthatacertainkindofbondwasinterestingforhim.
Thiskindofbondhasafixedvalue,andgivesafixedamountofyearlyinterest,payedtotheownerattheendofeachyear.Thebondhasnofixedterm.Bondsareavailableindifferentsizes.Thelargeronesusuallygiveabetterinterest.SoonJohnrealizedthattheoptimalsetofbondstobuywasnottrivialtofigureout.Moreover,afterafewyearshiscapitalwouldhavegrown,andtheschedulehadtobere-evaluated.
Assumethefollowingbondsareavailable:

ValueAnnual
interest
4000
3000
400
250
Withacapitalofe10000onecouldbuytwobondsof$4000,givingayearlyinterestof$800.Buyingtwobondsof$3000,andoneof$4000isabetteridea,asitgivesayearlyinterestof$900.Aftertwoyearsthecapitalhasgrownto$11800,anditmakessensetosella$3000oneandbuya$4000one,sotheannualinterestgrowsto$1050.Thisiswherethisstorygrowsunlikely:thebankdoesnotchargeforbuyingandsellingbonds.Nextyearthetotalsumis$12850,whichallowsforthreetimes$4000,givingayearlyinterestof$1200.
Hereisyourproblem:givenanamounttobeginwith,anumberofyears,andasetofbondswiththeirvaluesandinterests,findouthowbigtheamountmaygrowinthegivenperiod,usingthebestscheduleforbuyingandsellingbonds.
Input

ThefirstlinecontainsasinglepositiveintegerNwhichisthenumberoftestcases.Thetestcasesfollow.
Thefirstlineofatestcasecontainstwopositiveintegers:theamounttostartwith(atmost$1000000),andthenumberofyearsthecapitalmaygrow(atmost40).
Thefollowinglinecontainsasinglenumber:thenumberd(1<=d<=10)ofavailablebonds.
Thenextdlineseachcontainthedescriptionofabond.Thedescriptionofabondconsistsoftwopositiveintegers:thevalueofthebond,andtheyearlyinterestforthatbond.Thevalueofabondisalwaysamultipleof$1000.Theinterestofabondisnevermorethan10%ofitsvalue.
Output

Foreachtestcase,output–onaseparateline–thecapitalattheendoftheperiod,afteranoptimalscheduleofbuyingandselling.
SampleInput

1
100004
2
4000400
3000250

SampleOutput

14050
题目大意:给你M的钱,然后给你n种股票,每一种股票有一个价值和年收益,股票价值是1000的倍数,给你y年的时间,让你用手里的钱去买股票使得y年后手中的钱最多。
解题方法:完全背包,把第一年年终的钱用到第二年的投资上,一直到最后一年。


#include<stdio.h>
#include<iostream>
#include<string.h>
usingnamespacestd;

intmain()
{
intdp[50005];
intv[15],c[105];
intans,year,money,t;
intn;
scanf("%d",&n);
while(n--)
{
ans=0;
scanf("%d%d%d",&money,&year,&t);
for(inti=1;i<=t;i++)
{
scanf("%d%d",&c[i],&v[i]);
c[i]/=1000;
}
for(inti=0;i<year;i++)
{
ans=money/1000;
memset(dp,0,sizeof(dp));
for(intj=1;j<=t;j++)
{
for(intk=c[j];k<=ans;k++)
{
dp[k]=max(dp[k],dp[k-c[j]]+v[j]);
}
}
money+=dp[ans];
}
printf("%d\n",money);
}
return0;
}



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: