最大上升子序列长度

 1 //最长上升子序列 ,今晚偶尔想起来做了下,已经OJ测试 
 2 #include <iostream>
 3 #include <cstring>
 4 using namespace std;
 5 
 6 int a[100];
 7 //a数组记录以j为结尾的 长度 
 8 void solve(int *ans,int n)
 9 {
10     int i,j,k;
11     a[0] = 1;
12     for(i=1; i<n; i++)//必须从头开始算 
13     {
14         for(j=0; j<i; j++)
15         {
16             if(ans[j]<ans[i]&&(a[i]<(a[j]+1)))
17                 a[i] = a[j] + 1;
18         }  
19     }   
20 }
21 
22 int main()
23 {
24     int i,j,k;
25     int ans[100];
26     int n;
27     while(cin>>n)
28     {
29         memset(a,0,sizeof(a));
30         for(i=0; i<n; i++)
31             cin>>ans[i];        
32         solve(ans,n);
33         cout<<a[n-1]<<endl;
34     }
35     return 0;
36 }

   请将不如激将!

   因为公事只自己得利了那叫谋私利,若大家都得利了,那叫谋福利!

原文地址:https://www.cnblogs.com/hxsyl/p/2857965.html