HDU-1423-Greatest Common Increasing Subsequence-最长公共上升子序列【模版】
作者:互联网
This is a problem from ZOJ 2432.To make it easyer,you just need output the length of the subsequence.
InputEach sequence is described with M - its length (1 <= M <= 500) and M integer numbers Ai (-2^31 <= Ai < 2^31) - the sequence itself.Outputoutput print L - the length of the greatest common increasing subsequence of both sequences.Sample Input
1 5 1 4 2 5 -12 4 -12 1 2 4
Sample Output
2
注意一下控制格式
1 #include<stdio.h> 2 #include<iostream> 3 #include<algorithm> 4 #include<cmath> 5 #include<iomanip> 6 #include<string.h> 7 using namespace std; 8 9 int a[550]; 10 int b[550]; 11 int dp[550]; 12 13 int main() 14 { 15 std::ios::sync_with_stdio(false); 16 cin.tie(0); 17 cout.tie(0); 18 int tt; 19 cin>>tt; 20 while(tt--) 21 { 22 memset(a,0,sizeof(a)); 23 memset(b,0,sizeof(b)); 24 memset(dp,0,sizeof(dp)); 25 int p,q; 26 cin>>p; 27 for(int i=0;i<p;i++) 28 cin>>a[i]; 29 cin>>q; 30 for(int i=0;i<q;i++) 31 cin>>b[i]; 32 int maxx; 33 for(int i=0;i<p;i++) 34 { 35 maxx=0;//每次都要恢复 36 for(int j=0;j<q;j++) 37 { 38 if(a[i]>b[j]) 39 maxx=max(dp[j],maxx); 40 else if(a[i]==b[j]) 41 dp[j]=maxx+1; 42 } 43 } 44 int ans=0; 45 for(int i=0;i<q;i++) 46 ans=max(ans,dp[i]); 47 if(tt) 48 cout<<ans<<endl<<endl; 49 else 50 cout<<ans<<endl; 51 } 52 return 0; 53 }
标签:HDU,int,memset,1423,cin,Subsequence,include,dp,maxx 来源: https://www.cnblogs.com/OFSHK/p/11235714.html