poj_2063_ Full Backpack

Source: Internet
Author: User

Investment
Time Limit: 1000MS Memory Limit: 30000K
Total Submissions: 10090 Accepted: 3540

Description

John never knew he had a grand-uncle, until he received the notary ' s letter. He learned that He late Grand-uncle had gathered a lot of money, somewhere in South-america, and that John is the only I Nheritor.
John did not need this much money for the moment. But he realized that it would is a good idea to store this capital in a safe place, and has it grow until he decided to R Etire. The bank convinced him that a certain kind of bond is interesting for him.
This kind of bond have a fixed value, and gives a fixed amount of yearly interest, payed to the owner at the end of each ye Ar. The bond has a fixed term. Bonds is available in different sizes. The larger ones usually give a better interest. Soon John realized that the optimal set of bonds to buy is not trivial to figure out. Moreover, after a few years he capital would has grown, and the schedule had to be re-evaluated.
Assume the following bonds is available:
Value Annual
Interest
4000
3000
400
250

With a capital of E10 one could buy one bonds of $4, giving a yearly interest of $800. Buying bonds of $ $, and one of $4 is a better idea, as it gives a yearly interest of $900. After both years the capital have grown to $11, and it makes sense to sell a $ one and buy a $4 one, so the Ann UAL interest grows to $050. This is where the this story grows Unlikely:the bank does not charge for buying and selling bonds. Next year the total sum is 850, which allows for three times $4, giving a yearly interest of $200.
Here are your problem:given an amount to begin with, a number of years, and a set of bonds with their values and interests , find out how big the amount is grow in the given period, using the best schedule for buying and selling bonds.

Input

The first line contains a, positive integer N which is the number of the test cases. The test cases follow.
The first line of a test case contains-positive integers:the amount to start with (at most), and the Numbe R of years the capital is grow (at most 40).
The following line contains a single number:the number D (1 <= D <=) of available bonds.
The next D lines each contain the description of a bond. The description of a bond consists of the positive integers:the value of the bond, and the yearly interest for that bond. The value of a bond is always a multiple of $000. The interest of a bond is never more than 10% of its value.

Output

For each test case, output–on a separate line–the in the end of the period, after an optimal schedule of Buyin G and selling.

Sample Input

110000 424000 4003000 250

Sample Output

14050

Full backpack. The details of compression, such as type conversion, need to be noted.
#include <iostream>#include<cstring>#include<queue>#include<cstdio>#include<map>using namespacestd;structbond{intCost ; intInter;} bond[ the];intdp[100005];intMain () {intMoney ; intyear,t; scanf ("%d",&t);  while(t--) {scanf ("%d%d",&money,&Year ); intD; scanf ("%d",&d);  for(intI=0; i<d; i++) {scanf ("%d%d",&bond[i].cost,&bond[i].inter); Bond[i].cost/= +; } memset (DP,0,sizeof(DP));  for(intI=0; i<year;i++)        {            inttmp=money/ +;  for(intj=0; j<d;j++)                 for(intk=bond[j].cost;k<=tmp;k++) Dp[k]=max (dp[k],dp[k-bond[j].cost]+bond[j].inter); Money+=Dp[tmp]; } printf ("%d\n", Money); }    return 0;}

poj_2063_ Full Backpack

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.