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

理解再写。。。

Posted by litter at 2009-05-08 21:35:25 on Problem 1159
#include <iostream>
#include <string.h>
short ans[5001][5001];
using namespace std;
int main()
{
    int n;char str[5001];
    while(cin>>n)
    {
        getchar();gets(str);
        int l=strlen(str); int a=l-1,b=0;int i,j; 
		for(i=0;i<l;i++) ans[i][i]=1;
        for(i=a;i>=0;i--)
        for(j=i;j<l;j++)
        {
			if(str[i]!=str[j])ans[i][j]=ans[i+1][j]>=ans[i][j-1]?ans[i][j-1]+1:ans[i+1][j]+1;
			else ans[i][j]=ans[i+1][j-1]; 
		}  
        cout<<ans[0][l-1]<<endl;
    }
    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