POJ 1952 buy Low, buy lower[longest monotone sub-series deformation]

Source: Internet
Author: User

Title: POJ 1952 buy low, buy LOWER
Test instructions: Given a sequence, the longest monotonically descending subsequence is obtained, and then the number of sub-sequences is the longest in the case of the longest sub-sequence. (such as 3,2,1 and 3,2,1 belong to the same, can only count one)

Analysis: First use a DP "I" to indicate the length of the oldest sequence at the current I point
Use DP2 "I" to indicate the number of sub-sequences with the longest DP "I"
Then DP "I" = Max (dp "J") +1 (1<=j

/************************************problem:1952 user:y990041769memory:440k time:94mslanguage:g++ Result:acceptedsource code*************************/#include <cstdio>#include <cstdlib>#include <ctime>#include <cstring>#include <algorithm>#include <map>#include <vector>using namespace STD;Const intN =5500;intA[n];intDp[n],dp2[n];intNum[n];intCntintBin_search (intLintRintVal) { while(L&LT;=R) {intMid = (l+r)/2;if(num[mid]>val) L = mid+1;Elser = mid-1; }returnl;}intMain () {//Freopen ("Input.txt", "R", stdin);    intN while(~scanf("%d", &n)) { for(intI=1; i<=n; i++) {scanf("%d", &a[i]); Dp[i] = Dp2[i] =1; } for(intI=1; i<=n; i++) { for(intj=i-1; J>0; j--) {if(A[i]<a[j]) {if(dp[i]< (dp[j]+1)) {Dp[i] = dp[j]+1;                    Dp2[i] = Dp2[j]; }Else if(dp[i]== (dp[j]+1)) Dp2[i]+=dp2[j]; }Else if(A[i]==a[j]) {if(Dp[i] = =1) Dp2[i] =0; Break; }            }        }intMa =0; for(intI=1; i<=n; i++) ma = max (ma,dp[i]);intAns =0; for(intI=1; i<=n; i++)if(dp[i]==ma) ans + = dp2[i];printf("%d%d\n", Ma,ans); }return 0;}

POJ 1952 buy Low, buy lower[longest monotone sub-series deformation]

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.