mirror of
https://github.com/Kiritow/OJ-Problems-Source.git
synced 2024-03-22 13:11:29 +08:00
Create LCIS.cpp
This commit is contained in:
parent
86e65f21a9
commit
2f5b2cb6e3
29
.ACM-Templates/LCIS.cpp
Normal file
29
.ACM-Templates/LCIS.cpp
Normal 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
|
||||
|
Loading…
Reference in New Issue
Block a user