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 */