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

第一次自己写的dp,开心,哈哈

Posted by 1219194271qq at 2016-03-24 20:35:31 on Problem 1458
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;

int a[500][500];
char str1[500],str2[500];

int main()
{
    while(scanf("%s%s",str1,str2)!=EOF)
    {
        int len1=strlen(str1);
        int len2=strlen(str2);
        for(int i=0;i<=len1;i++)
            for(int j=0;j<=len2;j++)
            a[i][j]=0;

        for(int i=0;i<len1;i++){
            for(int j=0;j<len2;j++){
                if(str1[i]==str2[j])
                    a[i+1][j+1]=a[i][j]+1;
                else
                    a[i+1][j+1]=max(a[i][j+1],a[i+1][j]);
            }
        }

        printf("%d\n",a[len1][len2]);
    }
    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