UVA 11584 入门DP
一开始把它当成暴力来做了,即,从终点开始,枚举其最长的回文串,一旦是最长的,马上就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的更多相关文章
- 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 ...
- Partitioning by Palindromes UVA - 11584 简单dp
题目:题目链接 思路:预处理出l到r为回文串的子串,然后如果j到i为回文串,dp[i] = min(dp[i], dp[j] + 1) AC代码: #include <iostream> ...
- uva 11584 - 字符串 dp
题目链接 一个长度1000的字符串最少划分为几个回文字符串 ---------------------------------------------------------------------- ...
- 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 ...
- uva 11584 Partitioning by Palindromes 线性dp
// uva 11584 Partitioning by Palindromes 线性dp // // 题目意思是将一个字符串划分成尽量少的回文串 // // f[i]表示前i个字符能化成最少的回文串 ...
- UVA - 11584 划分字符串的回文串子串; 简单dp
/** 链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=34398 UVA - 11584 划分字符串的回文串子串: 简单 ...
- 区间DP UVA 11584 Partitioning by Palindromes
题目传送门 /* 题意:给一个字符串,划分成尽量少的回文串 区间DP:状态转移方程:dp[i] = min (dp[i], dp[j-1] + 1); dp[i] 表示前i个字符划分的最少回文串, 如 ...
- UVA 11584 一 Partitioning by Palindromes
Partitioning by Palindromes Time Limit:1000MS Memory Limit:0KB 64bit IO Format:%lld & %l ...
- HDU 1231 最大连续子序列 --- 入门DP
HDU 1231 题目大意以及解题思路见: HDU 1003题解,此题和HDU 1003只是记录的信息不同,处理完全相同. /* HDU 1231 最大连续子序列 --- 入门DP */ #inclu ...
随机推荐
- svn全局设置过滤文件没有作用的解决办法
svn全局设置过滤文件,网上教程文章很多, 都说了怎么配置,没有强调配置内容的格式 导致用惯了git的人,上手配置后,不起作用. 下面是我的配置内容: .classpath .project .set ...
- use matplotlib to draw scatter plot
There are many pionts in this kind of table. How to do it? We can use scatter() to draw it. Code: im ...
- JS - 查找字符串中的某个值,截取其之前。和之后的值
var str = "11:222"; /* * 截取 “ :”之前和之后的值 */document.write(str.split(':')[0]) //输出11doc ...
- cf754 754D - Fedor and coupons
2个多小时,弱智了..(连A都做不对,就不要做D了(迷)) #include<bits/stdc++.h> #define lowbit(x) x&(-x) #define LL ...
- Node.js NPM 教程
NPM是Node.js的包(或模块)管理器,是Node.js应用程序开发的核心. www.npmjs.com上有海量的Node.js包,供免费下载使用. 当安装Node.js时,NPM程序会被同时安装 ...
- Elasticsearch 使用集群 - 创建索引
章节 Elasticsearch 基本概念 Elasticsearch 安装 Elasticsearch 使用集群 Elasticsearch 健康检查 Elasticsearch 列出索引 Elas ...
- 5分钟搞懂:JWT(Json Web Token)
https://www.qikegu.com/easy-understanding/892 JWT 基于token的用户认证原理:让用户输入账号和密码,认证通过后获得一个token(令牌),在toke ...
- python+selenium 发送邮件
import time from selenium import webdriver from selenium.webdriver import ChromeOptions from seleniu ...
- Opencv调用深度学习模型
https://blog.csdn.net/lovelyaiq/article/details/79929393 https://blog.csdn.net/qq_29462849/article/d ...
- 进度5_家庭记账本App_数据库的添加和查看
今天继续在昨天的基础上完成了家庭记账单的在数据库中的添加和查看功能 在之前的基础上舍弃了Fragment,重新在百度上找到了学习资料,并且自我完成了实践 首先在之前的基础上创建CostListAdap ...