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<=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]