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 speedcell4 at 2011-07-19 17:10:53 on Problem 1458
#include<iostream>
#include<string>
#define SIZE 1001
using namespace std;
string a,b;
int opt[SIZE][SIZE]={0};
int findMax(int a,int b)
{
    return a>b?a:b;
}
int main()
{
    while(cin>>a>>b)
    {
        int count=0;
        for(int i=1,la=a.length();la-i>=0;i++)
        {
            for(int j=1,lb=b.length();lb-j>=0;j++)
            {
                opt[i][j]=0;
                if(a[i-1]==b[j-1]) opt[i][j]=findMax(opt[i][j],opt[i-1][j-1]+1);
                else opt[i][j]=findMax(opt[i-1][j],opt[i][j-1]);
                count=findMax(count,opt[i][j]);
            }
        }
        cout<<count<<endl;
    }
    return 0;
}

不明白为什么那么多人喜欢自己开字符数组,用string多方便的哇……

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