【CF1132F】Clear the String(动态规划)
【CF1132F】Clear the String(动态规划)
题面
题解
考虑区间\(dp\)。
增量考虑,每次考虑最后一个字符和谁一起删去,然后直接转移就行了。
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define MAX 505
int f[MAX][MAX],n;char s[MAX];
int main()
{
scanf("%d%s",&n,s+1);
for(int i=1;i<=n;++i)f[i][i]=1;
memset(f,63,sizeof(f));
for(int i=1;i<=n;++i)f[i][i-1]=0;
for(int r=1;r<=n;++r)
for(int l=1;l<=r;++l)
{
f[l][r]=f[l][r-1]+1;
for(int k=r-1;k;--k)
if(s[k]==s[r])
f[l][r]=min(f[l][r],f[l][k]+f[k+1][r-1]);
}
printf("%d\n",f[1][n]);
return 0;
}
【CF1132F】Clear the String(动态规划)的更多相关文章
- [CF1132F]Clear the String
题意 给你一个串s,每次可以花费1的代价删去一个子串,要求子串的每一位为同一个字符. 求删去整个串的最小代价. 分析 这是一道非常简单的区间\(DP\)问题,我们定义\(f[i][j]\)表示删去子串 ...
- 【CF1132F】Clear the String (DP)
/* 区间dp题目, 考虑当前区间l,r 是可以枚举最后一次拿的分界点来考虑最右边节点是不是具有贡献 */ #include<cstdio> #include<algorithm&g ...
- LeetCode 笔记系列 20 Interleaving String [动态规划的抽象]
题目: Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. For example,Given: ...
- HDU 5707 Combine String(动态规划)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5707 题意: 给你三个字符串 S1, S2, S3, 让你判断 S3 是否恰好由字符串 S1 和 S2 ...
- BestCoder Round #81 (div.2) 1004 String(动态规划)
题目链接:BestCoder Round #81 (div.2) 1003 String 题意 中文题,上有链接.就不贴了. 思路 枚举起点i,计算能够达到k个不同字母的最小下标j,则此时有子串len ...
- CodeForces-1132F Clear the String
题目链接 https://vjudge.net/problem/CodeForces-1132F 题面 Description You are given a string \(s\) of leng ...
- codeforces#1132 F. Clear the String(神奇的区间dp)
题意:给出一个字符串S,|S|<=500.每次操作可以删除一段连续的相同字母的子串.问,最少操作多少次可以把这个字符串变成空串. 分析:刚开始的思路是,把连续的串给删除掉,然后再....贪心.完 ...
- 【Codeforces 1132F】Clear the String
Codeforces 1132 F 题意:给一个串\(S\),问每次删除连续的一段相同字母,最少删几次将原串删空. 思路:考虑区间\(dp\),我们看要删多少次能把\([l,r]\)删空,那么最终答案 ...
- F. Clear the String(区间 DP )//每次都删除一个相同字符的子串 , 最小多少次
https://codeforces.com/contest/1132/problem/F 借鉴:https://www.cnblogs.com/chhokmah/p/10508762.html 题意 ...
随机推荐
- zabbix server3.4 使用mailx配置邮件报警
软件具体配置如下: 操作系统:Centos7.5 zabbix server版本:zabbix server3.4 zabbix agent版本:zabbix agent3.0 现在开始配置zabbi ...
- Android为TV端助力linux命令
从命令行push到系统目录,用户组是root,而代码里面的是个人用户组,所以要把你push进去的东西改成跟你APK一样的用户组,并且chmod -R 777 文件名修改文件的权限 修改用户组chown ...
- $符号报not defing 报错
https://blog.csdn.net/weixin_37969488/article/details/84250833 最近因为工作问题,需要我把别的项目上的一些jsp网页copy到新项目上.放 ...
- 01-vue学习之前的准备
一.具备的基础知识 1.扎实的HTML/CSS/Javascript基本功,这是前置条件. 2.不要用任何的构建项目工具,只用最简单的<script>,把教程里的例子模仿一遍,理解用法.不 ...
- java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start com ...
- Python编写脚本(输出三星形状的‘*’符号)
环境:python3.* 心得:个人认为脚本非我强项,以下效果可以有更简单解决方案,纯属练习逻辑. 方案一: s=1 while s<=10: #这是决定多少列,起始为1,大循环一圈即加一,就是 ...
- Saltstack_使用指南06_远程执行-指定目标
1. 主机规划 Targeting Minions文档 https://docs.saltstack.com/en/latest/contents.html 另请参见:自动化运维神器之saltstac ...
- Vue学习之路2-项目初搭建
1.检查环境是否全部安装成功 2.创建项目 2.1.打开dos命令窗口,使用dos命令转到项目文件夹下: 2.2.输入创建项目命令:vue init webpack myproject1 创建不同的打 ...
- Django框架【form组件】
from django.shortcuts import render,redirect # Create your views here. from .models import * from dj ...
- How To Size Your Apache Flink® Cluster: A Back-of-the-Envelope Calculation
January 11, 2018- Apache Flink Robert Metzger and Chris Ward A favorite session from Flink Forward B ...