Poj 2062 full backpack

Source: Internet
Author: User

Question in http://poj.org/problem? Id = 2063 previousArticleI practiced a complete backpack problem, and here I made another attempt to consolidate it. The so-called "lucky" is a coincidence.

The question probably means:

A total of m yuan is used for N years of investment. A total of K bonds can be bought.

(CI, ii) indicates that the intention is to call the CI, the year-end return of II

You can buy bonds at the beginning of each year and sell them again later.

Ask the maximum number of assets that can be changed in N years.

In fact, in N years of decision-making, each year is relatively independent. Therefore, simply considering a year is a complete backpack problem.

Backpack capacity is the total investment, and each item of the backpack is (bond cost, bond profit) to maximize the benefit of filling the backpack as much as possible. For more information, see the previous article or the nine articles about backpack.

My ACCodeAs shown in the following figure, there is a trick in it. In this topic, every bond cost is a factor of 1000, so we can think that less than 1000 of the current money is useless.

Therefore, when the decision is made every year, the total size of the backpack is the current total amount of money/1000, and the call charge for each bond is also divided by 1000.

For the choice of backpack capacity: because the initial amount of money is 1000 000 at most, and we divide it by 1000 and then it is 1000. And each return rate is up to 10%. after 40 years, the maximum return rate is 1.1 ^ 40 ≈ 45 259.

The Code is as follows:

# Include <stdio. h> # define max (x, y) (x)> (y )? (X) :( y) struct bond {int cost; int interest;}; int nbond; bond bonds [11]; int base; int DP [45300]; int getmaximum () {int I, j; for (I = 0; I <= base; I ++) {DP [I] = 0 ;}for (I = 0; I <nbond; I ++) {for (j = bonds [I]. cost; j <= base; j ++) {DP [J] = max (DP [J], DP [J-bonds [I]. cost] + bonds [I]. interest) ;}} return DP [base];} int main () {int ncase, nyears; scanf ("% d", & ncase); While (ncase --) {scanf ("% d", & base, & nyears); scanf ("% d", & nbond); int sum = base; For (INT I = 0; I <nbond; I ++) {scanf ("% d", & bonds [I]. cost, & bonds [I]. interest); bonds [I]. cost/= 1000;} For (INT I = 0; I <nyears; I ++) {base = sum/1000; sum + = getmaximum ();} printf ("% d \ n", sum);} return 0 ;}

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.