Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

0ms,没多大数据啊

Posted by KatrineYang at 2016-09-24 13:36:48 on Problem 1458
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator