1 solutions
-
0
C++ :
#include <iostream> #include <cstdio> #include <string> #include <algorithm> using namespace std; int dp[1010][1010]; int main() { //freopen("in.txt", "r", stdin); string a, b; int n; while (cin>>n) { while (n--) { cin>>a>>b; for (int i=1; i<=a.size(); i++) { for (int j=1; j<=b.size(); j++) { if (a[i-1]==b[j-1]) dp[i][j] = dp[i-1][j-1]+1; else dp[i][j] = max(dp[i-1][j], dp[i][j-1]); } } cout<<dp[a.size()][b.size()]<<endl; } } return 0; }
- 1
Information
- ID
- 746
- Time
- 3000ms
- Memory
- 64MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By