码迷,mamicode.com
首页 > 其他好文 > 详细

2016年团体程序设计天梯赛-模拟赛

时间:2016-05-16 01:54:22      阅读:384      评论:0      收藏:0      [点我收藏+]

标签:

L2-4. 最长对称子串

注意连续子串

技术分享
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <string>
#include <queue>
#include <vector>
#include <map>
#include <algorithm>

const int inf = 0x3f3f3f;
const int MAXN = 1e3+10;

using namespace std;

string ts1,ts2;
int dp[2][MAXN];

int main()
{
    while(getline(cin,ts1)){
       // transform(ts1.begin(),ts1.end(),ts1.begin(),::tolower);
        int len = ts1.size();
        ts2 = ts1;
        reverse(ts2.begin(),ts2.end());
       // cout<<ts2<<endl;
        int mmax = 0;
        memset(dp,0,sizeof(dp));
        for(int i=1;i<=len;i++){
            for(int j=1;j<=len;j++){
                if(ts1[i-1]==ts2[j-1]){
                    dp[i%2][j] = dp[(i-1)%2][j-1]+1;
                    mmax = max(mmax,dp[i%2][j]);
                }
                else
                    dp[i%2][j] = 0;
            }
        }
        cout<<mmax<<endl;
    }
    //cout << "Hello world!" << endl;
    return 0;
}
连续lcs

 

2016年团体程序设计天梯赛-模拟赛

标签:

原文地址:http://www.cnblogs.com/EdsonLin/p/5496700.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!