Educational Codeforces Round 61 (Rated for Div. 2)F(区间DP,思维,枚举)
#include<bits/stdc++.h>
typedef long long ll;
const int inf=0x3f3f3f3f;
using namespace std;
char b[507];
int dp[507][507];
int main(){
memset(dp,0x3f,sizeof(dp));
int n;
scanf("%d",&n);
scanf("%s",b+1);
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(i==j)
dp[i][j]=1;
else
dp[i][j]=inf;
for(int len=1;len<=n;len++)//中间段长度
for(int l=1,r;(r=l+len)<=n;l++)//枚举起点,枚举终点
if(b[l]==b[r])
if(len==1)
dp[l][r]=1;//初始为1
else
dp[l][r]=min(min(dp[l+1][r],dp[l][r-1]),dp[l+1][r-1]+1);//更新最小值
else
for(int k=l;k<r;k++)
dp[l][r]=min(dp[l][r],dp[l][k]+dp[k+1][r]);//区间更新
printf("%d",dp[1][n]);
}
//类似cf#538D
Educational Codeforces Round 61 (Rated for Div. 2)F(区间DP,思维,枚举)的更多相关文章
- Educational Codeforces Round 59 (Rated for Div. 2) E 区间dp + 状态定义 + dp预处理(分步dp)
https://codeforces.com/contest/1107/problem/E 题意 给出01字符串s(n<=100),相邻且相同的字符可以同时消去,一次性消去i个字符的分数是\(a ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...
- Educational Codeforces Round 71 (Rated for Div. 2)-F. Remainder Problem-技巧分块
Educational Codeforces Round 71 (Rated for Div. 2)-F. Remainder Problem-技巧分块 [Problem Description] ...
- Educational Codeforces Round 61 (Rated for Div. 2) D,F题解
D. Stressful Training 题目链接:https://codeforces.com/contest/1132/problem/D 题意: 有n台电脑,每台电脑都有初始电量ai,也有一个 ...
- Educational Codeforces Round 61 (Rated for Div. 2) E 多重背包优化
https://codeforces.com/contest/1132/problem/E 题意 有8种物品,重量是1~8,每种数量是\(cnt[i]\)(1e16),问容量为W(1e18)的背包最多 ...
- Educational Codeforces Round 61 (Rated for Div. 2)-C. Painting the Fence 前缀和优化
题意就是给出多个区间,要求去掉两个区间,使得剩下的区间覆盖范围最大. 当然比赛的时候还是没能做出来,不得不佩服大佬的各种姿势. 当时我想的是用线段树维护区间和,然后用单点判0,维护区间间断个数.然后打 ...
- Educational Codeforces Round 61 (Rated for Div. 2)
A. Regular Bracket Sequence 题意:给出四种括号的数量 (( )) () )( 问是否可以组成合法的序列(只能排序不能插在另外一个的中间) 思路: 条件一:一个或 n个) ...
- Educational Codeforces Round 61 (Rated for Div. 2) E. Knapsack
非常经典的dp题,因为1至8的最大公约数是840,任何一个数的和中840的倍数都是可以放在一起算的, 所以我只需要统计840*8的值(每个数字(1-8)的sum%840的总和),剩下都是840的倍数 ...
- Educational Codeforces Round 61 (Rated for Div. 2) G(线段树,单调栈)
#include<bits/stdc++.h>using namespace std;int st[1000007];int top;int s[1000007],t[1000007];i ...
随机推荐
- Composer + thinkphp5.1安装与使用
Composer 是 PHP 的一个依赖管理工具.我们可以在项目中声明所依赖的外部工具库,Composer 会帮你安装这些依赖的库文件,有了它,我们就可以很轻松的使用一个命令将其他人的优秀代码引用到我 ...
- Extjs5.0 学习之路【结构篇】
Extjs5.0在原有的MVC模式下增加了一个MVVM Extjs5.0项目文件执行顺序. 新增特性一 bind---data
- 机器学习:评价分类结果(ROC 曲线)
一.基础理解 1)定义 ROC(Receiver Operation Characteristic Curve) 定义:描述 TPR 和 FPR 之间的关系: 功能:应用于比较两个模型的优劣: 模型不 ...
- Django基础(五)
Django admin 自带的验证: from django.contrib.auth.decorators import login_required from django.contrib.au ...
- demo2 Kafka+Spark Streaming+Redis实时计算整合实践 foreachRDD输出到redis
基于Spark通用计算平台,可以很好地扩展各种计算类型的应用,尤其是Spark提供了内建的计算库支持,像Spark Streaming.Spark SQL.MLlib.GraphX,这些内建库都提供了 ...
- mina在spring中的配置多个端口
本次练习中是监听2个端口 applicationContext-mina.xml: <?xml version="1.0" encoding="UTF-8" ...
- java.nio.ByteBuffer中flip、rewind、clear方法的区别
对缓冲区的读写操作首先要知道缓冲区的下限.上限和当前位置.下面这些变量的值对Buffer类中的某些操作有着至关重要的作用: limit:所有对Buffer读写操作都会以limit变量的值作为上限. p ...
- App.CSharp.Grid的ICells接口
using System;using System.Collections.Generic;using System.Text;using System.Drawing;using System.Wi ...
- 【259】ucpole.dat update
2017年2月21日 57871 +0.020896 0.007232 +0.414732 0.009212 +0.418044 0.007533 p 57872 +0.022055 0.007284 ...
- springmvc 注解式开发 解决中文乱码问题