传送门

区间dp,记\(dp(l,r,t)\)表示区间\((l,r)\),\(t\)表示这个区间中能不能放\(M\)。如果可以,枚举中间哪里放\(M\)来压缩。也可以不压缩,后面直接跟上去。如果左右重复的,尝试压缩一下,那么循环节里是不能放的

//minamoto
#include<bits/stdc++.h>
using namespace std;
const int N=55,inf=0x3f3f3f3f;
char s[N];int f[N][N][2],n;
bool same(int L,int R){
if((R-L+1)&1)return false;int M=(R-L+1)>>1;
for(int i=L;i<L+M;++i)if(s[i]!=s[i+M])return false;return true;
}
int solve(int L,int R,bool is){
if(L==R)return 1;if(f[L][R][is])return f[L][R][is];int res=inf;
if(is)for(int i=L;i<R;++i)res=min(res,1+solve(L,i,1)+solve(i+1,R,1));
for(int i=L;i<R;++i)res=min(res,solve(L,i,is)+R-i);
if(same(L,R))res=min(res,solve(L,(L+R)>>1,0)+1);return f[L][R][is]=res;
}
int main(){
// freopen("testdata.in","r",stdin);
scanf("%s",s+1);n=strlen(s+1);
printf("%d\n",solve(1,n,1));return 0;
}

P2470 [SCOI2007]压缩的更多相关文章

  1. luogu P2470 [SCOI2007]压缩

    传送门 dalao们怎么状态都设的两维以上啊?qwq 完全可以一维状态的说 设\(f[i]\)为前缀i的答案,转移就枚举从前面哪里转移过来\(f[i]=min(f[j-1]+w(j,i))(j\in ...

  2. 洛谷P2470 [SCOI2007]压缩(区间dp)

    题意 题目链接 Sol 神仙题Orz 考虑区间dp,如果我们只设\(f[l][r]\)表示\(s_{lr}\)被压缩的最小长度,而不去关心内部\(M\)分布的话,可能在转移的时候转移出非法状态 因此考 ...

  3. BZOJ1068: [SCOI2007]压缩

    ... 1068: [SCOI2007]压缩 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 909  Solved: 566[Submit][Statu ...

  4. bzoj 1068: [SCOI2007]压缩 DP

    1068: [SCOI2007]压缩 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 496  Solved: 315[Submit][Status] D ...

  5. bzoj 1068 [SCOI2007]压缩 区间dp

    [SCOI2007]压缩 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 1644  Solved: 1042[Submit][Status][Discu ...

  6. [SCOI2007]压缩(动态规划,区间dp,字符串哈希)

    [SCOI2007]压缩 状态:设\(dp[i][j]\)表示前i个字符,最后一个\(M\)放置在\(j\)位置之后的最短字串长度. 转移有三类,用刷表法来实现. 第一种是直接往压缩串后面填字符,这样 ...

  7. 【洛谷P2470】[SCOI2007]压缩

    压缩 #include<iostream> #include<cstring> #include<cstdio> using namespace std; #def ...

  8. 洛谷P2470||bzoj1068 [SCOI2007]压缩

    bzoj1068 洛谷P2470 区间dp入门题?只要注意到每个M“管辖”的区间互不相交即可 错误记录:有点小坑,比如aaaacaaaac最优解为aRRcR(意会坑在哪里),踩了一次 #include ...

  9. BZOJ 1068: [SCOI2007]压缩

    Sol 区间DP.这个区间DP需要三维, \(f[i][j][k]\) 表示\([i,j]\) 这个区间中是否存在 \(M\) . 转移有两种,一种是这个区间存在 \(M\) ,那么直接枚举 \(M\ ...

随机推荐

  1. Session&Cookie 的介绍和使用

    Session介绍与使用 1.Session基本介绍 Session:在计算机中,尤其是在网络应用中,称为“会话控制”.Session 对象存储特定用户会话所需的属性及配置信息.这样,当用户在应用程序 ...

  2. cache and database

    This article referenced from http://coolshell.cn/articles/17416.html We all know that high concurren ...

  3. console command

    routes/console.php copy一个默认的 Artisan::command('hello', function () { $this->comment('hello world' ...

  4. Django学习系列之django分页

    基本语法实例 from django.core.paginator import Paginator objects = Post.objects.filter(status='published') ...

  5. 教程 | 使用Sqoop从MySQL导入数据到Hive和HBase

    基础环境 sqoop:sqoop-1.4.5+cdh5.3.6+78, hive:hive-0.13.1+cdh5.3.6+397, hbase:hbase-0.98.6+cdh5.3.6+115 S ...

  6. [React] Spread Component Props in JSX with React

    You often find duplication between the name of a prop and a variable you will assign to the prop. JS ...

  7. CSS 全部的列表样式类型

    <html> <head> <style type="text/css"> ul.none {list-style-type: none} ul ...

  8. 1062. Talent and Virtue (25)【排序】——PAT (Advanced Level) Practise

    题目信息 1062. Talent and Virtue (25) 时间限制200 ms 内存限制65536 kB 代码长度限制16000 B About 900 years ago, a Chine ...

  9. Java 编码 UTF-8

    近期在处理文件时发现了相同类型的文件使用的编码可能是不同的.所以想将文件的格式统一一下(由于UTF-8的通用性,决定往UTF-8统一),遇见的第一个问题是:怎样查看现有文件的编码方式. 文件编码问题集 ...

  10. WebSocket服务端

    http://blog.csdn.net/qq_20282263/article/details/54310737 C# 实现WebSocket服务端 原创 2017年01月10日 09:22:50 ...