201,400-degree star Preliminaries (second field)--best Financingproblem Description Small A wants to maximize profits through reasonable investment banking products. Known as small A in the next period of time in the income situation, descriptive narrative is two length of an integer array of n dates and earnings, expressed in the dates[i] Day small a income earnings[i] yuan (0<=i<n). The financial products introduced by the Bank are determined by the period and the profit, and can be described as three integer arrays of length m, start, Finish and interest_rates, and if the purchase of a factoring product I (0<=I<M), the principal must be invested in the first start[i] days, Finish[i] days can be retrieved principal and proceeds, during which the principal and income can not be retrieved, the proceeds of the principal *interest_rates[i]/100.0. The purchase of financial products on the same day as the proceeds of the same day or the maturity of the financial products (Note: The proceeds obtained from purchasing a financial product cannot be used to purchase a possible financial product) without considering compounding. Assuming that idle money has no other benefits, such as current income, all proceeds can only be obtained by purchasing these financial products. Find the maximum benefit that small a can get.
Restrictions:
1<=n<=2500
1<=m<=2500
For random I (0<=i<n), 1<=dates[i]<=100000,1<=earnings[i]<=100000, there is no repeating element in dates.
For casual I (0<=i<m), 1<=start[i]<finish[i]<=100000, 1<=interest_rates[i]<=100.
Input first Behavior T (t<=200), which represents the number of input data groups.
The data formats for each group are as follows:
The first line is N m
Successive n rows, each of which is two spaces-delimited integers, in turn, date and earning
After the continuous m line, each behavior three spaces separated by the integer, start, Finish and Interest_rate
Output to group I data, I start from 1, outputs
Case #i:
Profit value, reserved two digits after the decimal point, rounded.
Sample Input
21 21 100001 100 550 200 102 21 100005 200001 5 65 9 7
Sample Output
Case #1:1000.00Case #2:2700.00
SOURCE2014 Baidu Star Program Design contest-Preliminary (second round)
The correct test instructions are:
Tell you n time points, these time points you will get a certain amount of money.
Then tell you the M time period, and the corresponding interest rate (percentage) for the time period.
Ask how much money you can get at the end.
Precautions
First the proceeds cannot be used to purchase
the day you get the money, you can now spend it. the same day as finish is available for purchase.
Analysis
After understanding the test instructions, the mind will think that this is the Tao DP problem.
Then look at each time point to get the money, it seems that they are independent of each other.
Actually see this is independent after. is very good to do.
For the money at a certain point in time, we run backwards over time, and we meet some time periods.
For the time period encountered. We have two options: 1. Buy 2. Not buy.
Buy our time to move to the end of this time period, do not buy our time to move to the next moment.
The last money to get is: current Money * The sum of the interest rate for the selected time period.
Suggest yourself to draw a picture to see. Or think about it in your heart.
Because our goal is to be the most profitable, that is to choose the time period of interest rate and maximum.
This problem can easily write the state transition equation:
dp[i] = max (Dp[i], dp[j] + rate[i, j]);
where dp[i] represents the maximum interest rate on the route to the last time and Dp[i], the initial value can be dp[i + 1], that is, the time period starting at this point is not selected.
Rate[i, j] represents a time period from I to J, and the interest rate for this time period is Rate[i, J].
This way we can preprocess the maximum interest rate for the entire time point to the last time by scanning from the back forward.
Then we multiply the current time's money by the optimal interest rate for the current time and that is the current best interest.
The above analysis is from the blog:
id=670 ">http://tiankonguse.com/record/record.php?
id=670AC Code:
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #define MAX 100005using namespace std;typedef struct money{int dates;int earnings;} money;typedef struct Earn{int start;int finish;int rate;} Earn;bool CMP (const Earn &l,const Earn &r) {return l.start<r.start;} int Dp[max]; Money Money[max]; Earn Earn[max];int N,m,maxtime;long Long ans;void dp () {memset (dp,0,sizeof (DP)); m--;for (int i=maxtime;i>=0;i--) {DP [I]=dp[i+1];while (M>=0&&i==earn[m].start) {Dp[i]=max (dp[i],dp[earn[m].finish]+earn[m].rate); m--;}}} int main (int argc,char *argv[]) {int t;scanf ("%d", &t), for (int i=1;i<=t;i++) {scanf ("%d%d", &n,&m); maxtime=0;for (int j=0;j<n;j++) {scanf ("%d%d", &money[j].dates,&money[j].earnings); Maxtime=max (MaxTime, money[j].dates);} for (int k=0;k<m;k++) {scanf ("%d%d%d", &earn[k].start,&earn[k].finish,&earn[k].rate); Maxtime=max ( Maxtime,earn[k].finish);} Sort (earn,earn+m,cmp);DP(); ans=0;for (int j=0;j<n;j++) ans+=mOney[j].earnings*dp[money[j].dates];p rintf ("Case #%d:\n", i);p rintf ("%i64d.%0 2i64d\n ", ans/100,ans%100);} return 0;}
201,400-degree star Preliminaries (second field)--best financing