1. 程式人生 > >【暑假】[深入動態規劃]UVa 1412 Fund Management

【暑假】[深入動態規劃]UVa 1412 Fund Management


Frank is a portfolio manager of a closed-end fund for Advanced Commercial Markets (ACM ). Fund collects money (cash) from individual investors for a certain period of time and invests cash into various securities in accordance with fund's investment strategy. At the end of the period all assets are sold out and cash is distributed among individual investors of the fund proportionally to their share of original investment.

Frank manages equity fund that invests money into stock market. His strategy is explained below.

Frank's fund has collected c<tex2html_verbatim_mark> US Dollars (USD) from individual investors to manage them for m<tex2html_verbatim_mark> days. Management is performed on a day by day basis. Frank has selected n

<tex2html_verbatim_mark> stocks to invest into. Depending on the overall price range and availability of each stock, a lot size was chosen for each stock -- the number of shares of the stock Frank can buy or sell per day without affecting the market too much by his trades. So, if the price of the stock is p
i<tex2html_verbatim_mark> USD per share and the lot size of the corresponding stock is si<tex2html_verbatim_mark> , then Frank can spend pisi<tex2html_verbatim_mark> USD to buy one lot of the corresponding stock for his fund if the fund has enough cash left, thus decreasing available cash in the fund. This trade is completely performed in one day.

When price of the stock changes to p'i<tex2html_verbatim_mark> later, then Frank can sell this lot for p'isi<tex2html_verbatim_mark> USD, thus increasing available cash for further trading. This trade is also completely performed in one day. All lots of stocks that are held by the fund must be sold by the end of the fund's period, so that at the end (like at the beginning) the fund is holding only cash.

Each stock has its own volatility and risks, so to minimize the overall risk of the fund, for each stock there is the maximum number of lots ki<tex2html_verbatim_mark> that can be held by the fund at any given day. There is also the overall limit k<tex2html_verbatim_mark> on the number of lots of all stocks that the fund can hold at any given day.

Any trade to buy or sell one lot of stock completely occupies Frank's day, and thus he can perform at most one such trade per day. Frank is not allowed to buy partial lots if there is not enough cash in the fund for a whole lot at the time of purchase.

Now, when fund's period has ended, Frank wants to know what is the maximum profit he could have made with this strategy having known the prices of each stock in advance. Your task is to write a program to find it out.

It is assumed that there is a single price for each stock for each day that Frank could have bought or sold shares of the stock at. Any overheads such as fees and commissions are ignored, and thus cash spent to buy or gained on a sell of one lot of stock is exactly equal to its price on this day multiplied by the number of shares in a lot.

Input 

Input consists on several datasets. The first line of each dataset contains four numbers -- c<tex2html_verbatim_mark> , m<tex2html_verbatim_mark> , n<tex2html_verbatim_mark> , and k<tex2html_verbatim_mark> . Here c<tex2html_verbatim_mark>(0.01$ \le$c$ \le$100000000.00)<tex2html_verbatim_mark> is the amount of cash collected from individual investors up to a cent (up to two digits after decimal point); m<tex2html_verbatim_mark>(1$ \le$m$ \le$100)<tex2html_verbatim_mark> is the number of days in the fund's lifetime; n<tex2html_verbatim_mark>(1$ \le$n$ \le$8)<tex2html_verbatim_mark> is the number of stocks selected by Frank for trading;k<tex2html_verbatim_mark>(1$ \le$k$ \le$8)<tex2html_verbatim_mark> is the overall limit on the number of lots the fund can hold at any time.

The following 2n<tex2html_verbatim_mark> lines describe stocks and their prices with two lines per stock.

The first line for each stock contains the stock name followed by two integer numbers si<tex2html_verbatim_mark> and ki<tex2html_verbatim_mark> . Here si<tex2html_verbatim_mark>(1$ \le$si$ \le$1000000)<tex2html_verbatim_mark> is the lot size of the given stock, and ki<tex2html_verbatim_mark>(1$ \le$ki$ \le$k)<tex2html_verbatim_mark> is the number of lots of this stock the fund can hold at any time. Stock name consists of 1 to 5 capital Latin letters from `` A" to `` Z". All stock names in the input file are distinct.

The second line for each stock contains m<tex2html_verbatim_mark> decimal numbers separated by spaces that denote prices of the corresponding stock for each day in the fund's lifetime. Stock prices are in range from 0.01 to 999.99 (inclusive) given up to a cent (up to two digits after decimal point).

Cash and prices in the input file are formatted as a string of decimal digits, optionally followed by a dot with one or two digits after a dot.

For each dataset, write to the output file m + 1<tex2html_verbatim_mark> lines. Print a blank line between datasets.

On the first line write a single decimal number -- the precise value for the maximal amount of cash that can be collected in the fund by the end of its period. The answer will not exceed 1 000 000 000.00. Cash must be formatted as a string of decimal digits, optionally followed by a dot with one or two digits after a dot.

On the following m<tex2html_verbatim_mark> lines write the description of Frank's actions for each day that he should have made in order to realize this profit. Write BUY followed by a space and a stock name for buying a stock. Write SELL followed by a space and a stock name for selling a stock. Write HOLD if nothing should have been done on that day.

144624.00 9 5 3 
IBM 500 3 
97.27 98.31 97.42 98.9 100.07 98.89 98.65 99.34 100.82 
GOOG 100 1 
467.59 483.26 487.19 483.58 485.5 489.46 499.72 505 504.28 
JAVA 1000 2 
5.54 5.69 5.6 5.65 5.73 6 6.14 6.06 6.06 
MSFT 250 1 
29.86 29.81 29.64 29.93 29.96 29.66 30.7 31.21 31.16 
ORCL 300 3 
17.51 17.68 17.64 17.86 17.82 17.77 17.39 17.5 17.3
151205.00 
BUY GOOG 
BUY IBM 
BUY IBM 
HOLD 
SELL IBM 
BUY MSFT 
SELL MSFT 
SELL GOOG 
SELL IBM

相關推薦

暑假[深入動態規劃]UVa 1412 Fund Management

Frank is a portfolio manager of a closed-end fund for Advanced Commercial Markets (ACM ). Fund collects money (cash) from individual investors for a certa

演算法動態規劃

含義     動態規劃(dynamic programming)是運籌學的一個分支,是求解決策過程(decision process)最優化的數學方法。 分類     動態規劃一般可分為線性動規,

20180406python--動態規劃演算法思維學習

我們已經掌握了較為常用和簡單的分治演算法思維,那麼在分治的基礎上,我們通過對比來學習動態規劃的演算法思維。 動態規劃(Dynamic Programming,簡稱DP)演算法思維常見於某類最優化問題,此類問題其絕大部分不能通過窮舉和遍歷來推導,相當一部分不能通過簡單遞迴來實現,而是需要進行多階段的

USACO16OPEN248 動態規劃

題目描述 Bessie likes downloading games to play on her cell phone, even though she doesfind the small touch screen rather cumbersome t

UVa 1412 - Fund Management(狀壓DP + 預處理)

out code clas https continue amp 註意 emp 最後一天 鏈接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_

Luogu關卡2-16線性動態規劃(2017年10月)

all -1 要掌握 span pan nbsp 關卡 線性結構 這也 任務說明:這也是基礎的動態規劃。是在線性結構上面的動態規劃,一定要掌握。 P1020 導彈攔截 導彈攔截 合唱隊形 尼克的任務 石子合並 低價購買 多米諾骨牌【Luogu】

動態規劃常見動態規劃題目總結

此部落格是為總結動態規劃常見題目。 嗯,當然也包含了大量非動態規劃問題。 題目型別真亂。 題目1:word break 1.1 題目描述: Given a string s and a dictionary of words dict, determine if

重點 遞迴 動態規劃 正則表示式匹配LeetCode 10. Regular Expression Matching

LeetCode 10. Regular Expression Matching Solution1:遞迴 程式碼中的註釋寫的不是太清楚,加一點: 一、當模式中的第二個字元不是“*”時: 1、如果字串第一個字元和模式中的第一個字元相匹配,那麼

HDU 動態規劃(46道題目)傾情奉獻~ 只提供思路與狀態轉移方程

Robberies http://acm.hdu.edu.cn/showproblem.php?pid=2955 揹包;第一次做的時候把概率當做揹包(放大100000倍化為整數):在此範圍內最多能搶多少錢 最腦殘的是把總的概率以為是搶N家銀行的概率之和… 把狀態轉移方程寫

深入理解C++的動態繫結和靜態繫結

為了支援c++的多型性,才用了動態繫結和靜態繫結。理解他們的區別有助於更好的理解多型性,以及在程式設計的過程中避免犯錯誤。 需要理解四個名詞: 1、物件的靜態型別:物件在宣告時採用的型別。是在編譯期確定的。 2、物件的動態型別:目前所指物件的型別。是在執行期決定的。物件的

jzoj3418NOIP動態規劃專題選課樹型依賴動態規劃

description 大學裡實行學分。每門課程都有一定的學分,學生只要選修了這門課,並通過考核就能獲得相應的學分。學生最後的學分是他各門課學分的總和。每個學生都要選擇規定數量的課程。其中有些課程可以直接選修,有些課程需要一定的基礎知識,必須在選了其他的一些課

資料結構與演算法 DP 動態規劃 介紹

最近在看演算法導論。 DP全稱是dynamic programming,這裡programming不是程式設計,是一個表格儲存之前的結果。 DP 是一種程式設計思想,主要用於解決最優解型別的問題。 其思路是為了求解當前的問題的最優解,使用子問題的最優解,然後綜合處理,最終得

南陽理工acm 1070詭異的電梯動態規劃

詭異的電梯【Ⅰ】 時間限制:1000ms  |  記憶體限制:65535KB 難度:3 描述 新的宿舍樓有 N(1≤N≤100000) 層and M(1≤M≤100000)個學生.在新的宿舍樓裡, 為了節約學生的時間也為了鼓勵學生鍛鍊身體,所以規定該宿舍樓裡的電梯

(轉載)DP專輯ACM動態規劃總結

動態規劃(英語:Dynamic programming,DP)是一種在數學、電腦科學和經濟學中使用的,通過把原問題分解為相對簡單的子問題的方式求解複雜問題的方法。 動態規劃常常適用於有重疊子問題和最優子結構性質的問題,動態規劃方法所耗時間往往遠少於樸素解

SCCM部署規劃

sccm 規劃 sccm 本篇主要對SCCM的前期規劃進行討論。 1.Active Directory整合 在ConfigMgr部署中,可以選擇CofigMgr和現有的Active Directory進行整合,既然整合與否並非強制性的,那與Active Directo

原創datagridview動態綁定contextmenustrip,並復制單元格數據

event args oar cells ren .get add cell ntc public class DGVCopy { public DataGridView DataGridViewCopy { get; set; }

java深入了解JAVA可變長度的參數

這一 args 必須 滿足 深入 itl 重載 編碼 創建 到J2SE 1.4為止,一直無法在Java程序裏定義實參個數可變的方法——因為Java要求實參(Arguments)和形參(Parameters)的數量和類型都必須逐一匹配,而形參的數目是在

Pythonpython動態類型

引用變量 區分 如何工作 回收 new images 如何 空間 簡單的 在python中,省去了變量聲明的過程,在引用變量時,往往一個簡單的賦值語句就同時完成了,聲明變量類型,變量定義和關聯的過程,那麽python的變量到底是怎樣完成定義的呢? 動態類型  

深入理解margin

盒模型 mbed 推理 日誌 onf cap limited textarea 效果 由淺入深漫談margin屬性 2007-3-18 上午 - HTML/CSS/XML/XSL - CSS - margin margin 在中文中我們翻譯成外邊距或者外補白(

知識深入理解js閉包

nts 存在 window 依次 ner hat 再看 tex 程序 本文轉載: 一、變量的作用域 要理解閉包,首先必須理解Javascript特殊的變量作用域。 變量的作用域無非就是兩種:全局變量和局部變量。 Javascript語言的特殊之處,就在於函數內部可以直接讀取