1578: [Usaco2009 feb]stock Market stock time limit:10 Sec Memory limit:64 MB
submit:414 solved:199
[Submit] [Status] [Discuss] Description
Although cows are inherently cautious, they are still being hit in the housing mortgage market, and they are now embarking on the stock market. Bessie very prescient, she not only know today S (2 <= S <= 50) only stock prices, but also know the next total of D (2 <= D <= 10) days (including today). Given a D-day stock price matrix (1 <= price <= 1000) and the initial capital m (1 <= m <= 200,000), an optimal trading strategy is made to maximize total profit. Every time you have to buy an integer multiple of the stock price, you don't have to spend all the money (or even spend it). There is no way to make your profit more than 500,000. Consider the example of this bull market (this is Bessie's favorite). In this example, there are s=2 only stocks and d=3 days. Cows have 10 of their money to invest. Today's Price | Tomorrow's Price | | The day after tomorrow's price stock | | | 1 10 15 15 2 13 11 20 The maximum profit is obtained by the following strategy, and the first stock is bought on the first day. Sell it the next day and buy the second one quickly, leaving 4 of the money. The last day to sell the second stock, at this time a total of 4+20=24 money.
Input
* First line: Three spaces separated by integers: S, D, M
* 2nd. S+1 Line: Line s+1 contains the 1th s stock only. D-Day Price
Output
* First line: The most likely amount of money after the last day of selling the stock.
Sample Input2 3 10
10 15 15
13 11 20
Sample Output -HINT Source
Gold
The puzzle: (I would say I started thinking about DP?) Even think of BZOJ3359 like to build a diagram to find the shortest-circuit hehe)
It's actually DP ... A slightly hidden backpack, will be the price of the previous day as a price, the following days of the value (the political haunting ah ah, there is wood), set up a complete knapsack problem, and then slowly play (B[i in this program) is the current day of money left I can create the greatest value, and then hand push down)
1/**************************************************************2Problem:15783 User:htotbug4 language:pascal5 result:accepted6Time:9176Ms7Memory:4140KB8****************************************************************/9 Ten var One I,j,k,l,n,m,tot:longint; AA:Array[0.. the,0.. -] ofLongint; -b:array[0..1000005] ofLongint; - functionMax (x,y:longint): Longint; the begin - ifX>y ThenMax:=xElsemax:=y; - End; - begin + readln (n,m,l); - fori:=1 toN Do + forj:=1 toM Do A read (a[i,j]); attot:=l; - fori:=2 toM Do - begin - forj:=0 toTot Dob[j]:=J; - forj:=1 toN Do - begin in ifa[j,i]>a[j,i-1] Then - fork:=a[j,i-1] toTot DoB[k]:=max (b[k-a[j,i-1]]+a[j,i],b[k]); to End; +tot:=B[tot]; - End; the writeln (tot); * End.
1578: [Usaco2009 Feb]stock Market