Created
June 23, 2014 10:12
-
-
Save KPCCoiL/03e99e7699ea2ae31eff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <cstring> | |
#include <algorithm> | |
using namespace std; | |
int main(){ | |
string s,t; | |
cin>>s>>t; | |
int n = s.length(),m = t.length(); | |
int dp[n][m]; | |
for (int i = 0; i < n; i++) { | |
for (int j = 0; j < m; j++) { | |
if(!i) dp[i][j] = j?dp[i][j-1]:0 || s[i] == t[j]; | |
else if(!j) dp[i][j] = dp[i-1][j] || s[i] == t[j]; | |
else dp[i][j] = max(dp[i-1][j],dp[i][j-1]) + (s[i] == t[j]); | |
} | |
} | |
cout << dp[n-1][m-1] << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment