HDU 1159 裸最长公共子串

试着拍了一道模板题

dp开了500,开100会超时.....

string类型中间有空格会判为结束

#include<algorithm> -->min,max函数的头文件

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;
int main()
{
    string s,t;
    int dp[500][500];
    while(cin>>s)
    {
        int i,j,m=0,n=0;
        memset(dp,0,sizeof(dp));
        n=s.length();
        cin>>t;
        m=t.length();
        for(i=0;i<n;i++)
        {
            for(j=0;j<m;j++)
            {
                if(s[i]==t[j])
                {
                    dp[i+1][j+1]=dp[i][j]+1;
                }
                else
                {
                    dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);
                }
            }
        }
        cout<<dp[n][m]<<endl;
    }
    return 0;
}
原文地址:https://www.cnblogs.com/dzzy/p/5271740.html