Poj2063 investment-full backpack

Source: Internet
Author: User

Question:

There are d kinds of stocks, each of which has a purchase amount and income,You have the principal C. What is the maximum investment income after year?

Analysis:

Here, we can know that each type of stock can be purchased for an unlimited number of times, so we can see that it is a full backpack problem, and we can regard the principal C as a backpack. But you need to handle it)

Let's take a look at the benefits of one year and analyze the DP process:

DP [I] [J] indicates the maximum benefit of J when considering the I-th stock. Pass the previousFull backpack in VernacularWe can understand that this can be optimized to a one-dimensional array.

However, considering that the DP array cannot be too large and the stock price is a multiple of 1000, what we need to deal with here is to divide each amount by 1000.

At the same time, for every year, we get the greatest benefit from a full backpack, and then give all the money to the full backpack next year.

Mount:

 
// # Include <stdio. h> # include <string. h> # define Max 50005int N; // case int D; // number of stock sets int V [11], in [11]; // value interest int ans [Max]; // DP array int dp (INT pre) {memset (ANS, 0, sizeof (ANS); For (INT I = 1; I <= D; I ++) {for (Int J = V [I]; j <= pre; j ++) {ans [J] = ans [J]> ans [J-V [I] + in [I]? Ans [J]: ANS [J-V [I] + in [I];} return ans [pre];} int main () {int C, year; // start fund scanf ("% d", & N); While (n --) {scanf ("% d", & C, & year, & D); For (INT I = 1; I <= D; I ++) {scanf ("% d", & V [I], & in [I]); V [I]/= 1000;} For (INT I = 1; I <= year; I ++) // multiple full backpacks {C ++ = dp (C/1000);} printf ("% d \ n", c);} return 0 ;} /* 110000 424000 4003000 250 */

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.