P1108 low price purchase, p1108 low price purchase

Source: Internet
Author: User

P1108 low price purchase, p1108 low price purchase

Description
The "buy at a low price" recommendation is half the rule of success in the dairy market. To be considered a great investor, you must follow the following questions and suggestions: "low price purchase; low price purchase again ". Every time you buy a stock, you must purchase it at a lower price than the price you purchased it last time. The more times you buy, the better! Your goal is to follow the above suggestions and ask you for the maximum number of times you can buy a stock. You will be given the daily sale price of a stock within a period of time (a positive integer in the range of 2 ^ 16), you can choose on which days to buy this stock. Each purchase must follow the principle of "low price purchase; then low price purchase. Write a program to calculate the maximum number of purchases.

Here is the price list of a stock:

Date 1 2 3 4 5 6 7 8 9 10 11 12

Price 68 69 54 64 68 70 67 78 62 98 87

The best investors can buy up to four shares. One of the feasible schemes is:

Date 2 5 6 10

Price 69 68 64 62

Input/Output Format
Input Format:
Row 3: N (1 <= N <= 1st), stock issuance days

Row 2nd: N number, which is the stock price per day.

Output Format:
The output file contains only two rows: the maximum number of purchases and the maximum number of purchases (<= 2 ^ 31) when the two schemes "look the same" (that is, they make up the same price Queue), these two schemes are considered to be the same.

Input and Output sample
Input example #1: Copy
BUYLOW. IN
12
68 69 54 64 68 64 70 67 78 62 98 87
Output example #1: Copy
BUYLOW. OUT
4 2

Calculate the maximum length and number of dropped sub-sequences (deduplication)

 
# Include <bits/stdc ++. h> using namespace std; # define maxn 10000 typedef long ll; # define inf 0x3f3f3fint n; int a [maxn]; int f [maxn], c [maxn]; int ans1, ans2; int main () {cin> n; for (int I = 1; I <= n; I ++) cin> a [I]; for (int I = n; I> = 1; I --) {f [I] = 1; for (int j = I + 1; j <= n; j ++) if (a [I]> a [j]) f [I] = max (f [I], f [j] + 1 ); ans1 = max (ans1, f [I]) ;}for (int I = n; I> = 1; I --) {if (f [I] = 1) c [I] = 1; for (int j = I + 1; j <= n; j ++) // If the length is the same as the current point, set the number of the previous vertex to 0 to prevent repeated if (f [I] = f [j] & a [I] = a [j]) c [j] = 0; // in this case, I must be able to connect to j first, so I need to transmit data from c [j, then f [I] has a new path, so it is + = else if (f [j] + 1 = f [I] & a [I]> a [j]) c [I] + = c [j];} for (int I = 1; I <= n; I ++) if (f [I] = ans1) ans2 + = c [I]; // here c [I] has saved all potential cout <ans1 <"" <ans2; return 0 ;}

 

Related Article

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.