一开始把它当成暴力来做了,即,从终点开始,枚举其最长的回文串,一旦是最长的,马上就ans++,再计算另外的部分。。。结果WA了

事实证明就是一个简单DP,算出两个两个点组成的线段是否为回文,再用LCS的类似做法得到每个子结构的最优值。

#include <cstdio>
#include <cstring>
#define N 1010
char s[N];
int n,len,d[N][N],sum[N];
int min(int a,int b)
{
if (a<b) return a;
return b;
}
int ok(int a,int b)
{
for (int i=a,j=b;i<j;i++,j--)
{
if (s[i]!=s[j]) return ;
}
return ;
}
int main()
{
scanf("%d",&n);
for (int i=;i<n;i++)
{
scanf("%s",s);
len=strlen(s);
int k,q,ans=;
for (int i=;i<len;i++)
{
sum[i]=N;
for (int j=;j<=i;j++)
{
d[j][i]=ok(j,i);
}
}
sum[]=;
for (int i=;i<len;i++)
{
for (int j=;j<=i;j++)
{
//printf("%d %d %d\n",j,i,d[j][i]);
if (d[j][i])
{
int tmp;
if (j>)
{
tmp=+sum[j-];
}
else
tmp=;
sum[i]=min(sum[i],tmp);
}
}
}
printf("%d\n",sum[len-]);
}
return ;
}

UVA 11584 入门DP的更多相关文章

  1. UVA 674 (入门DP, 14.07.09)

     Coin Change  Suppose there are 5 types of coins: 50-cent, 25-cent, 10-cent, 5-cent, and 1-cent. We ...

  2. Partitioning by Palindromes UVA - 11584 简单dp

    题目:题目链接 思路:预处理出l到r为回文串的子串,然后如果j到i为回文串,dp[i] = min(dp[i], dp[j] + 1) AC代码: #include <iostream> ...

  3. uva 11584 - 字符串 dp

    题目链接 一个长度1000的字符串最少划分为几个回文字符串 ---------------------------------------------------------------------- ...

  4. UVA - 11584 Partitioning by Palindromes[序列DP]

    UVA - 11584 Partitioning by Palindromes We say a sequence of char- acters is a palindrome if it is t ...

  5. uva 11584 Partitioning by Palindromes 线性dp

    // uva 11584 Partitioning by Palindromes 线性dp // // 题目意思是将一个字符串划分成尽量少的回文串 // // f[i]表示前i个字符能化成最少的回文串 ...

  6. UVA - 11584 划分字符串的回文串子串; 简单dp

    /** 链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=34398 UVA - 11584 划分字符串的回文串子串: 简单 ...

  7. 区间DP UVA 11584 Partitioning by Palindromes

    题目传送门 /* 题意:给一个字符串,划分成尽量少的回文串 区间DP:状态转移方程:dp[i] = min (dp[i], dp[j-1] + 1); dp[i] 表示前i个字符划分的最少回文串, 如 ...

  8. UVA 11584 一 Partitioning by Palindromes

    Partitioning by Palindromes Time Limit:1000MS     Memory Limit:0KB     64bit IO Format:%lld & %l ...

  9. HDU 1231 最大连续子序列 --- 入门DP

    HDU 1231 题目大意以及解题思路见: HDU 1003题解,此题和HDU 1003只是记录的信息不同,处理完全相同. /* HDU 1231 最大连续子序列 --- 入门DP */ #inclu ...

随机推荐

  1. 032.SAP上用户无法打开PPE模块,查看并开通用户的PPE权限

    01. 用户使用PPE模块之后,提示没有为iPPE工作台分配一个用户参数,如图所示: 02. 如果是管理员账号,则可以点击右下角的问号,来到下面界面 03.点击iPPE 用户分配者几个蓝色的字,进入下 ...

  2. http error 502.5

    原文地址:https://www.cnblogs.com/loui/p/7826073.html 在部署网站时遇到的各种问题,通过检索找到了解决方案,感谢!!记录一下以免忘记.. 解决方法:把IIS的 ...

  3. 01 DDL(DataDefinitionLanguage)

    注: 语句用 ; 或 \g \G 表示结束 .       建库语句 :         CREATE DATABASE db_name ;          查询有哪些库 :         SHO ...

  4. SQL注入汇总(手注,盲注,报错注入,宽字节,二次编码,http头部){10.22、23 第二十四 二十五天}

    首先什么是SQL注入: 所谓SQL注入,就是通过把SQL命令插入到Web表单提交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意的SQL命令. SQL注入有什么危害? 危害:数据泄露.脱库 ...

  5. tornado+peewee-async+peewee+mysql(一)

    前言: 需要异步操作MySQL,又要用orm,使用sqlalchemy需要加celery,觉得比较麻烦,选择了peewee-async 开发环境 python3.6.8+peewee-async0.5 ...

  6. 解决dispatch 后在当前页面不能获取最新的this.props中的数据

    因为dispatch为异步方法  .解决这个问题方法很多  出去添加定时器这种不是很优雅的方法  我们可以用 componentWillReceiveProps(nextProps) 这个生命周期  ...

  7. 压测工具siege和wrk

    siege压测工具 安装: wget http://download.joedog.org/siege/siege-3.0.8.tar.gz cd siege-3.0.8 ./configure ma ...

  8. C# Stream篇(七) -- NetworkStream

    NetworkStream 目录: NetworkStream的作用 简单介绍下TCP/IP 协议和相关层次 简单说明下 TCP和UDP的区别 简单介绍下套接字(Socket)的概念 简单介绍下Tcp ...

  9. OpenPose 开源库安装

    一.下载openpose下载openpose 使用Git直接下载openpose git clone https://github.com/CMU-Perceptual-Computing-Lab/o ...

  10. c++程序—while猜数字游戏

    #include<iostream> using namespace std; #include<string> #include<ctime> int main( ...