POJ 2063 Investment
2013-08-01 19:12
323 查看
[b]Investment[/b]
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:
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
SampleOutput
TimeLimit:1000MS | MemoryLimit:30000K | |
TotalSubmissions:6836 | Accepted:2367 |
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:
Value | Annual interest |
4000 3000 | 400 250 |
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; }
相关文章推荐
- POJ 2063 Investment
- POJ 2063 Investment【完全背包】
- poj 2063 Investment
- poj 2063Investment
- POJ 2063 Investment
- POJ 2063 Investment(完全背包)
- POJ 2063 Investment
- Poj 2063 Investment
- POJ-2063 Investment (完全背包 简单题)
- poj 2063 Investment
- POJ 2063 Investment
- [POJ 2063] Investment (动态规划)
- POJ 2063 Investment 变形的完全背包
- POJ 2063 Investment(完全背包)
- POJ - 2063 Investment(01背包)
- poj 2063 Investment
- POJ 2063 Investment (完全背包)
- POJ 2063 Investment【经典完全背包】
- POJ 2063 Investment (完全背包)
- Poj 2063 Investment (完全背包)