hiho week 162 register

Ended

Participants:319

Verdict:Accepted
Score:100 / 100
Submitted:2017-08-07 15:02:50

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
const int mod=1000000007;
typedef long long ll;
const int maxn=105;
int main()
{
    int i,j,len,dp[maxn][maxn],start,end;
    char a[maxn];
    while(scanf("%s",a)!=EOF)
    {
        memset(dp,0,sizeof(dp));
        len=strlen(a);
        for(i=2;i<=len;i++)
        {
            for(j=0;j<=len-i;j++)
            {
                start=j;end=j+i-1;
                if(a[start]==a[end])
                dp[start][end]=dp[start+1][end-1];
                else
                {
                    dp[start][end]=min(dp[start+1][end]+1,dp[start][end-1]+1);
                    //cout<<dp[start][end]<<' '<<start<<' '<<end<<endl;
                    if(start+1<=end-1)
                    dp[start][end]=min(dp[start][end],dp[start+1][end-1]+1);
                    else
                    dp[start][end]=min(dp[start][end],1);
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX