| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
0ms,没多大数据啊#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
const int MX = 2333;
int dp[MX][MX];
char s1[MX], s2[MX];
int mx(int a, int b){
return (a>b) ? a : b;
}
int main() {
while(scanf("%s%s", s1, s2) == 2){
int l1 = strlen(s1), l2 = strlen(s2);
for(int i = 0; i <= l1; i++){
for(int j = 0; j <= l2; j++){
if(!(i*j)) dp[i][j]=0;
else if(s1[i-1]==s2[j-1]){
dp[i][j]=dp[i-1][j-1]+1;
}
else dp[i][j]=mx(dp[i-1][j],dp[i][j-1]);
}
}
printf("%d\n",dp[l1][l2]);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator