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

why tle?

Posted by direfire at 2006-10-15 06:55:54 on Problem 1458
#include <iostream> 
#include <sstream> 
#include <string> 
#include <vector> 
#include <set> 
#include <map> 
#include <algorithm> 
#include <cstdio> 
#include <cstdlib> 
#include <cmath>
#include <math.h>
#include <string.h>
#include <stdlib.h>
using namespace std; 

#define REP(i, n) for(int i = 0; i<(n); i++) 
#define abs(a) ((a) >= 0 ? (a) : -(a)) 
#define inf 999999999 
typedef vector<int> VI; 
typedef vector<string> VS; 
typedef long long i64; 
typedef unsigned long long u64;


char a[1000];
char b[1000]; 
int dp[1000][1000];
int na, nb;

int go(int pos1, int pos2)
{
	
	if (dp[pos1][pos2] != -1) return dp[pos1][pos2];
	if (pos1 == 0 && pos2 == 0)
		return dp[0][0] = 0;
	int res = 0;
	for (int i = pos2-1; i >= 0; i--)
	{
		for (int j = pos1-1; j >= 0; j--)
		{
			if (b[i] == a[j]) {
				int tmp = 1+go(j, i);
				if (tmp > res) res = tmp;
			}		
		}
	}
//	printf("%d, %d %d\n", pos1, pos2, res);	
	return dp[pos1][pos2] = res;
}

int main()
{
	while(1)
	{
		cin>>a>>b;
		na = strlen(a); nb = strlen(b);
		memset(dp, -1, sizeof(dp));
		printf("%d\n", go(na, nb));
	}
}

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