From 2f5b2cb6e3ce321ec5ae2320893e5977ce71b8bd Mon Sep 17 00:00:00 2001 From: KiritoTRw <3021577574@qq.com> Date: Thu, 11 Aug 2016 09:04:27 +0800 Subject: [PATCH] Create LCIS.cpp --- .ACM-Templates/LCIS.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .ACM-Templates/LCIS.cpp diff --git a/.ACM-Templates/LCIS.cpp b/.ACM-Templates/LCIS.cpp new file mode 100644 index 0000000..23ca374 --- /dev/null +++ b/.ACM-Templates/LCIS.cpp @@ -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 +