日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Stock Market(luogu 2938)

發布時間:2025/7/14 编程问答 16 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Stock Market(luogu 2938) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目描述

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.

Today's price

| Tomorrow's price

| | Two days hence Stock | | | 1 10 15 15

2 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.

有S種股票,我們已經知道每一天每一種股票的價格。一共有d天,一開始擁有的錢為m,求最后總共能夠擁有多少錢。

輸入輸出格式

輸入格式:

?

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

?

輸入輸出樣例

輸入樣例
2 3 10 10 15 15 13 11 20 輸出樣例
24

Measure:

我們來好好推下這個DP--

  

在第二天,我們能取得的最大收益:

第一種股票第一天10元買入,第二天15元賣出,收益5元

第二種股票第一天……買不起!只有10元

所以,第二天我們就有15元啦。(開心)

在第三天,我們能取得的最大收益:

第一種股票第二天再買沒錢賺了

第二種股票第二天則可以低價買入,高價賣出,收益9元

?

其實我一開始有些疑惑,我本來以為最便宜的時候買入,在最貴的時候賣出才應該最優

而DP的思路則是有錢賺就賣

現在驗證,它是對的。

假如我們一開始有 m=10 元,一種股票三天價格如下

5 10 20

按我的想法:第一天花10元買入兩股,第三天20元賣出,收益:40-10=30

按DP的做法:第一天花10元買入兩股,第二天10元賣出,收益:20-10=10,m=20;第三天有錢賺,又第二天賣出兩股【就相當于沒賣】,收益:+(40-20)= 30

并不影響

?

code(開 O(2) 才過)

#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; const int MX=510000; int n,d,m,f[MX],pri[110][20];int main() {scanf("%d%d%d",&n,&d,&m);for(int i=1;i<=n;++i) for(int j=1;j<=d;++j) scanf("%d",&pri[i][j]); for(int k=2;k<=d;++k) { //前 k 天 int mx=0;memset(f,0,sizeof(f));for(int i=1;i<=n;++i) { //第 i 種股票 for(int j=pri[i][k-1];j<=m;++j) { //花 j 元 f[j]=max(f[j],f[j-pri[i][k-1]]+pri[i][k]-pri[i][k-1]); mx=max(mx,f[j]);}}m+=mx; }printf("%d",m);return 0; }

?

轉載于:https://www.cnblogs.com/qseer/p/9777188.html

總結

以上是生活随笔為你收集整理的Stock Market(luogu 2938)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 日本xxxx18| 久久艹免费视频 | av网址导航 | 在线观看h视频 | 久久久精品免费看 | 日韩激情视频一区二区 | 肉色超薄丝袜脚交一区二区图片 | 色图综合 | 三级欧美视频 | 人人97| www.日韩欧美 | 中文字幕久久久久 | 天天躁日日躁狠狠躁喷水 | 国产污污在线观看 | 亚洲国产成人精品激情在线 | 国产在线免费av | 国产人妻777人伦精品hd | 亚洲综合另类小说 | 成人免费福利 | 91久久精品一区二区别 | 致命魔术电影高清在线观看 | 精品人妻av在线 | 日韩精品福利 | 高清不卡一区二区 | 中国老熟女重囗味hdxx | 91丨九色丨蝌蚪丨老版 | 天天干干 | www.好吊色 | 国产色一区 | 草草福利影院 | 国产精品久久不卡 | 熟妇人妻无乱码中文字幕真矢织江 | 亚洲字幕在线观看 | 土耳其xxxx性hd极品 | 久操伊人| 精久久久久久久 | 日本在线资源 | 一级毛片儿 | 色呦呦网站入口 | 久久久国产精品黄毛片 | 精品少妇久久久久久888优播 | 永久av| avav国产| 久久亚洲精品视频 | 久久发布国产伦子伦精品 | 久久精品一区二区三区四区 | 亚洲精品777| 制服丝袜av在线播放 | 青青草原国产在线观看 | 综合久久激情 | www.777奇米 | 日日爱886| 欧美做受高潮动漫 | 在线黄色网页 | 久久久久久久久久久久91 | 朝桐光av在线一区二区三区 | 亚洲熟女乱色综合亚洲av | 涩涩片影院 | 欧美一区二区视频在线观看 | 桃色在线视频 | 影音先锋在线视频 | 亚洲天堂网在线观看视频 | 美国黄色av | 日韩在线网址 | 欧美一级一级 | 亚洲色偷精品一区二区三区 | 在线观看亚洲成人 | 杏导航aⅴ福利网站 | 国产区一二三 | 日韩综合第一页 | 制服丝袜在线第一页 | 欧美一区欧美二区 | 高清欧美性猛交xxxx | 朝鲜一级黄色片 | 九色porn蝌蚪 | h文在线观看 | 国产成人精品777777 | 在线免费观看成人 | 国产精品一区av | 久久riav| 亚洲人人精品 | 精品丰满人妻无套内射 | 中文字幕在线观看第一页 | 国产一区午夜 | 一级片在线观看免费 | 香蕉av在线播放 | 国产伦精品一区二区三区 | 日韩黄片一区二区 | 91美女诱惑 | 夜夜爽爽| 人与动物av| 黄页网站在线播放 | 国产一国产精品一级毛片 | 久久久精品久久久 | 欧美性xxxx图片 | 丰满少妇影院 | 人妻精品无码一区二区三区 | 高清免费毛片 | 欧美黑人猛交 |