Chinaunix首页 | 论坛 | 博客
  • 博客访问: 198230
  • 博文数量: 67
  • 博客积分: 2970
  • 博客等级: 少校
  • 技术积分: 685
  • 用 户 组: 普通用户
  • 注册时间: 2010-07-23 11:36
文章分类

全部博文(67)

文章存档

2012年(2)

2011年(19)

2010年(46)

我的朋友

分类: C/C++

2010-08-06 11:38:47

解题思路:

amount(i,j)代表字符序列从i到j需要插入的个数

 

#include<stdio.h>


char g[5001];
short amount[5000][5000];

short min(short x,short y)
{
    return x>y?y:x;
}

int main()
{
    int n;
    scanf("%d%s",&n,g);
    for(int i=n-1;i>=0;i--)
    {
        for(int j=i;j<n;j++)
        {
            if(g[i]==g[j])
            {
                amount[i][j]=amount[i+1][j-1];
            }else
            {
                amount[i][j]=1+min(amount[i+1][j],amount[i][j-1]);
            }
        }
    }
    printf("%d\n",amount[0][n-1]);
    return 0;
}


阅读(1375) | 评论(0) | 转发(0) |
0

上一篇:pku1466 Girls and Boys

下一篇:pku1151 Atlantis

给主人留下些什么吧!~~