201,400-degree star Preliminaries (second field)--best financing

Source: Internet
Author: User

201,400-degree star Preliminaries (second field)--best Financingproblem Description Small A wants to maximize profits through reasonable investment banking products. Known small A in the next period of time in the income situation. The description is described as an integer array of two length 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&LT;=I&LT;M), the principal must be invested in the first start[i] days, The principal and proceeds can be retrieved at Finish[i] days. During this period, the principal and the income can not be retrieved, the profit is 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. Suppose that idle money has no other benefit. such as current income, all proceeds can only be obtained through purchase of 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 behavior is two integers separated by a space. Date and earning in turn
followed by a continuous m line. Three spaces-delimited integers for each behavior, start, Finish, and Interest_rate
Output to group I data. I start from 1, output
Case #i:
Profit value. Keep 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 take a look at every point in time to get the money. It seems that they are independent of each other.

Actually see this is independent after, it 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 your own heart to think about.

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]);
among dp[I] stands for I time point to the maximum interest rate on the course of the last time and. The initial value of Dp[i] can be dp[i + 1], that is, the time period to start at this point is not selected.

Rate[i, J] stands for 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.

above analysis from blog: 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;}


Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.

201,400-degree star Preliminaries (second field)--best financing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.