Create LCIS.cpp

This commit is contained in:
KiritoTRw 2016-08-11 09:04:27 +08:00 committed by GitHub
parent 86e65f21a9
commit 2f5b2cb6e3

29
.ACM-Templates/LCIS.cpp Normal file
View File

@ -0,0 +1,29 @@
/// LCIS 最长公共上升子序列
namespace LCIS
{
const int MAXLEN_A = 500;
const int MAXLEN_B = 500;
int dp[MAXLEN_A+5][MAXLEN_B+5];
int deal(const char* a,const char* b)
{
int lena=strlen(a);
int lenb=strlen(b);
for(int i=1;i<=lenb;i++)
{
int k=0;
for(int j=1;j<=lena;j++)
{
dp[i][j]=dp[i-1][j];/// when b[i-1] != a[j-1]
if(b[i-1]>a[j-1]) k=max(k,dp[i-1][j]);
else if(b[i-1]==a[j-1]) dp[i][j]=k+1;
}
}
int ans=0;
for(int i=1;i<=lena;i++) ans=max(ans,dp[lenb][i]);
return ans;
}
}
//End of namespace LCIS