题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1257
题意:经典题。
题解:最长上升子序列。
代码:
1 #include <iostream> 2 #include <algorithm> 3 #include <cstdio> 4 #include <cstring> 5 #include <string> 6 #define ll long long 7 using namespace std; 8 const int maxn = 30005; 9 10 int a[maxn]; 11 int dp[maxn]; 12 int main(){ 13 int n; 14 while(cin>>n){ 15 for(int i = 1; i <= n ;i++){ 16 cin>>a[i]; 17 dp[i] = 1; 18 } 19 //转成上升 20 for(int i = 1 ;i <= n; i++){ 21 for(int j = 1; j < i ;j++){ 22 if(a[j] < a[i]){ 23 dp[i] = max(dp[i],dp[j] + 1); 24 } 25 } 26 } 27 28 int maxx = -1; 29 30 for(int i = 1; i <= n ;i++) 31 maxx = max(dp[i],maxx); 32 cout<<maxx<<endl; 33 } 34 return 0; 35 }