2019/09/29 19:55

# JDOJ 2625: USACO 2009 Feb Gold 2.Stock Market

JDOJ传送门

## 题目描述

Despite their innate prudence, the cows took a beating in the home mortgage market and now are trying their hand at stocks. Happily, Bessie is prescient and knows not only today's S (2 <= S <= 50) stock prices but also the future stock prices for a total of D days (2 <= D <= 10).

Given the matrix of current and future stock prices on various days (1 <= PR_sd <= 1,000) and an initial M (1 <= M <= 200,000) units of money, determine an optimal buying and selling strategy in order to maximize the gain realized by selling stock on the final day. Shares must be purchased in integer multiples, and you need not spend all the money (or any money). It is guaranteed that you will not be able to earn a profit of more than 500,000 units of money.

Consider the example below of a bull (i.e., improving) market, the kind Bessie likes most. In this case, S=2 stocks and D=3 days. The cows have 10 units of money to invest.

|Stock|Today's price| Tomorrow's price| | Two days hence Stock | | | :-----------: | :-----------: | :-----------: | :-----------: | | AA | 10 | 15 | 15 | |BB | 13| 11|20 |

If money is to be made, the cows must purchase stock 1 on day 1. Selling stock 1 on day 2 and quickly buying stock 2 yields 4 money in the bank and one share of 2. Selling stock 2 on the final day brings in 20 money for a total of 24 money when the 20 is added to the bank.

## 输入格式

* Line 1: Three space-separated integers: S, D, and M

* Lines 2..S+1: Line s+1 contains the D prices for stock s on days 1..D: PR_sd

## 输出格式

* Line 1: The maximum amount of money possible to have after selling on day D.

AA 10 15 15
BB 13 11 20

# 输出格式

## 题解：

``````#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int s,d,m,maxx;
int map[60][20],dp[500001];
int main()
{
scanf("%d%d%d",&s,&d,&m);
for(int i=1;i<=s;i++)
for(int j=1;j<=d;j++)
scanf("%d",&map[i][j]);
for(int i=2;i<=d;i++)
{
maxx=-1;
memset(dp,0,sizeof(dp));
for(int j=1;j<=s;j++)
for(int k=map[j][i-1];k<=m;k++)
{
dp[k]=max(dp[k],dp[k-map[j][i-1]]+map[j][i]-map[j][i-1]);
maxx=max(maxx,dp[k]);
}
m+=maxx;
}
printf("%d",m);
return 0;
}
``````

0
0 收藏

0 评论
0 收藏
0