POJ--2063 -- investors -- backpack, 002063 shares

Source: Internet
Author: User

POJ--2063 -- investors -- backpack, 002063 shares

Investment
Time Limit:1000 MS   Memory Limit:30000 K
Total Submissions:8733   Accepted:2984

Description

John never knew he had a grand-uncle, until he got the notary's letter. he learned that his late grand-uncle had gathered a lot of money, somewhere in South-America, and that John was the only inheritor.
John did not need that much money for the moment. but he realized that it wocould be a good idea to store this capital in a safe place, and have it grow until he decided to retire. the bank convinced him that a certain kind of bond was interesting for him.
This kind of bond has a fixed value, and gives a fixed amount of yearly interest, payed to the owner at the end of each year. the bond has no fixed term. bonds are available in different sizes. the larger ones usually give a better interest. soon John realized that the optimal set of bonds to buy was not trivial to figure out. moreover, after a few years his capital wowould have grown, and the schedule had to be re-evaluated.
Assume the following bonds are available:
Value Annual
Interest
4000
3000
400
250

With a capital of e10 000 one cocould buy two bonds of $4 000, giving a yearly interest of $800. buying two bonds of $3 000, and one of $4 000 is a better idea, as it gives a yearly interest of $900. after two years the capital has grown to $11 800, and it makes sense to launch a $3 000 one and buy a $4 000 one, so the annual interest grows to $1 050. this is where this story grows unlikely: the bank does not charge for buying and selling bonds. next year the total sum is $12 850, which allows for three times $4 000, giving a yearly interest of $1 200.
Here is 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 may grow in the given period, using the best schedule for buying and selling bonds.

Input

The first line contains a single positive integer N which is the number of test cases. The test cases follow.
The first line of a test case contains two positive integers: the amount to start with (at most $1 000 000 ), and the number of years the capital may grow (at most 40 ).
The following line contains a single number: the number d (1 <= d <= 10) of available bonds.
The next d lines each contain the description of a bond. the description of a bond consists of two positive integers: the value of the bond, and the yearly interest for that bond. the value of a bond is always a multiple of $1 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 capital at the end of the period, after an optimal schedule of buying and selling.

Sample Input

110000 424000 4003000 250

Sample Output

14050

There are multiple deposit schemes, each of which has two attribute values: A and B, indicating that you need to save A dollar for this scheme, and the interest is B yuan per year, the first input is N and K. You have N of money, which requires the maximum amount of money you can get in K years.

Resolution: This is an ordinary full backpack, but note that the value is too large and can be opportunistic, because the number of savings in each solution is A multiple of 1000, therefore, you can record the index after dividing it by 1000, but you may think of an error. For example, if the principal is 1010, 1010/1000 = 1 at this time, don't worry, you think, is there a difference between saving 1000 and saving 1010? Is this 10 yuan useful ?, The deposit scheme is a multiple of 1000, so you don't need to worry about the zero-head. You can add it at that time. My approach here is: Because every profit is less than 10%, so I went to the principal X (110%) ^ K to get the maximum possible amount of money. Divide the number by 1000 as the maximum capacity of the backpack, in DP [X], the interest is generated when the deposit is set to X, so that after I finish the backpack, I record sum = N + (N + DP [M]). + (N + DP [N] + DP [N + DP [N]) ...... in this case, K times later .... You will understand.


# Include <iostream> # include <cstdio> # include <cstring> # include <algorithm> # define Max (a, B) a> B? A: busing namespace std; int dp [111111]; struct node {int val, interest;} s [11]; int main (void) {int t, n, m, i, j, k, l, p; scanf ("% d", & t); while (t -- & scanf ("% d", & m, & l) {scanf ("% d", & n); k = m; for (I = 0; I <l; I ++) {k = 1.1 * k; // use K to multiply m by the L power of 1.1} k/= 1000; for (I = 0; I <n; I ++) {scanf ("% d", & s [I]. val, & s [I]. interest); s [I]. val/= 1000; // The amount of money saved in the solution divided by 1000} memset (dp, 0, sizeof (dp); for (I = 0; I <n; I ++) // directly complete the backpack for (j = s [I]. val; j <= k; j ++) dp [j] = Max (dp [j], dp [j-s [I]. val] + s [I]. interest); while (l> 0) // calculate the total interest after l years {l --; m + = dp [m/1000]; // Add the annual interest and change M to the principal of that year.} printf ("% d \ n", m) ;}return 0 ;}

Summary: this is a way to narrow down the capacity according to the conditions. When you are doing a question, you must fully explore all the methods that can be simplified according to the known conditions. In some cases, this is the answer, just like this question, if it won't be so simplified, you should wait for GG to die...


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.