一开始把它当成暴力来做了,即,从终点开始,枚举其最长的回文串,一旦是最长的,马上就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. 盘姬工具箱WV1.10

    ========================================================================== {盘姬工具箱CruiserEXPforWin版是一 ...

  2. Linux应用可通过USB访问Android设备-Chrome OS 75版发布

    导读 谷歌已经为支持的Chromebook设备发布了Chrome OS 75操作系统,这是一个主要版本,增加了各种新功能,最新安全补丁和其他改进. 对于大多数Chromebook设备,Chrome O ...

  3. Ubuntu不会放弃32位应用程序

    Ubuntu 开发人员澄清,人们以为 Ubuntu 将在 Ubuntu 19.10 和后续版本中放弃对运行 32 位应用程序的支持,但“根本不是这种情况”.那么这究竟是怎么一回事呢?前几天 Ubunt ...

  4. 动手实验01-----vCenter 微软AD认证配置与用户授权

    环境说明: AD域->   centaline.net 阅读目录: 1. 配置与AD认证源 2.权限角色 1. 配置与AD认证源 登陆vCenter后,在 系统管理 -> 配置 -> ...

  5. apache启动错误:Could not reliably determine the server's fully qualified domain name

    启动apache遇到错误:httpd: Could not reliably determine the server's fully qualified domain name [root@serv ...

  6. Vulkan 之 Layers

    Layers 暴露给api层,不像传统图形API集成在驱动里面,开发者根据自己的需要进行开启,最终目的还是为了提高性能. The Loader he loader is the central arb ...

  7. python中添加requests资源包

    1.进入资源网址下载:https://www.lfd.uci.edu/~gohlke/pythonlibs/ 2.按下CTRL+F进行页面查找“requests” 3.点击requests-2.22. ...

  8. 039-PHP使用闭包函数来进行父实例的变量自增,错误示例

    <?php // 如何使用闭包函数来进行父实例的变量自增,错误示例 function demo(){ $num = 1; $func = function() use($num){ echo $ ...

  9. c# 多张图片合成一张图片

    using System; using System.Collections.Generic; using System.Drawing; using System.IO; using System. ...

  10. JS笔记03

    JS图片库 标记 需求效果: 网页中的图片链接显示在网页中的图片框内部而不是打开新的页面 //html部分 <!DOCTYPE html> <html> <head> ...