看代码就懂了 不解释 3 1 1 1 1 2 2 2 1 1 1 3 第一个3 和最后一个 3 只需要一个就够了,,,
1 #include<iostream> 2 #include<cstring> 3 #include<algorithm> 4 #include<stdio.h> 5 #include<cmath> 6 using namespace std; 7 8 int dp[5005],num[5005],arr[5005]; 9 int main( ) 10 { 11 int N; scanf("%d",&N); 12 for( int i = 1; i <= N; i++ ) 13 { 14 scanf("%d",&arr[i]); 15 dp[i] = num[i] = 1; 16 } 17 int Max = 0; 18 for( int i = 2; i <= N; i++ ) 19 for( int j = i-1; j >= 1; j-- ) 20 if( arr[i] < arr[j] ) 21 { 22 if( dp[j]+1 > dp[i] ) 23 { 24 dp[i] = dp[j]+1; 25 num[i] = num[j]; 26 }else if( dp[j]+1 == dp[i] ) 27 num[i] += num[j]; 28 }else if( arr[i] == arr[j] ) 29 { 30 if( dp[i] == 1 )num[i] = 0; 31 break; 32 } 33 for( int i = 1; i <= N; i++ ) 34 Max = max( Max,dp[i] ); 35 int res = 0; 36 for( int i = 1; i <= N; i++ ) 37 if( dp[i] == Max )res+=num[i]; 38 cout<<Max<<" "<<res<<endl; 39 return 0; 40 }