洛谷P2470||bzoj1068 [SCOI2007]压缩
区间dp入门题?只要注意到每个M“管辖”的区间互不相交即可
错误记录:有点小坑,比如aaaacaaaac最优解为aRRcR(意会坑在哪里),踩了一次
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<cassert>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
int an[][];
bool v1[][];
int tmp[];
char s[];
int n;
int solve(int l,int r)
{
assert(l<=r);
if(l==r) return ;
if(v1[l][r]) return an[l][r];
int ans=0x3f3f3f3f;
for(int i=l;i<r;++i)
ans=min(ans,solve(l,i)+solve(i+,r));
tmp[l-]=;
for(int p=l;p<=r;++p)
{
tmp[p]=tmp[p-]+;
if((p-l+)%==&&!strncmp(s+l,s+l+(p-l+)/,(p-l+)/))
tmp[p]=min(tmp[p],tmp[l+(p-l+)/-]+);
}
ans=min(ans,tmp[r]+(l!=));
//printf("1t%d %d %d\n",l,r,ans);
v1[l][r]=;
return an[l][r]=ans;
}
int main()
{
scanf("%s",s+);n=strlen(s+);
printf("%d\n",solve(,n));
return ;
}
洛谷P2470||bzoj1068 [SCOI2007]压缩的更多相关文章
- 【洛谷P2470】[SCOI2007]压缩
压缩 #include<iostream> #include<cstring> #include<cstdio> using namespace std; #def ...
- 洛谷 1052 dp 状态压缩
洛谷1052 dp 状态压缩 传送门 (https://www.luogu.org/problem/show?pid=1052#sub) 做完这道题之后,感觉涨了好多见识,以前做的好多状压题目都是将一 ...
- 洛谷p1052过河 路径压缩+dp
洛谷 P1052 过河 思路部分可以看这篇博客 我将在这里对其进行一些解释与补充 首先我们先看题 乍一看 这不是模板题吗 然后开开心心的敲了一个简单dp上去 #include<iostream& ...
- BZOJ1068: [SCOI2007]压缩
... 1068: [SCOI2007]压缩 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 909 Solved: 566[Submit][Statu ...
- 【洛谷2053】 [SCOI2007]修车(费用流)
传送门 洛谷 Solution 考虑把每一个修车工人拆成\(n\)个点,那么考虑令\(id(i,j)\)为第\(i\)个工人倒数第\(j\)次修车. 然后就可以直接跑费用流了!!! 代码实现 /* m ...
- 洛谷P2470 [SCOI2007]压缩(区间dp)
题意 题目链接 Sol 神仙题Orz 考虑区间dp,如果我们只设\(f[l][r]\)表示\(s_{lr}\)被压缩的最小长度,而不去关心内部\(M\)分布的话,可能在转移的时候转移出非法状态 因此考 ...
- BZOJ1068 [SCOI2007]压缩 区间动态规划 字符串
欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ1068 题目概括 (其实是复制的) 给一个由小写字母组成的字符串,我们可以用一种简单的方法来压缩其中 ...
- 2018.10.20 bzoj1068: [SCOI2007]压缩(区间dp)
传送门 这题转移很妙啊. f[l][r][1/0]f[l][r][1/0]f[l][r][1/0]表示对于区间[l,r][l,r][l,r]有/无重复的机会时压缩的最小值. 那么可以从三种情况转移过来 ...
- BZOJ1068 [SCOI2007]压缩 【区间dp】
题目 给一个由小写字母组成的字符串,我们可以用一种简单的方法来压缩其中的重复信息.压缩后的字符串除了小 写字母外还可以(但不必)包含大写字母R与M,其中M标记重复串的开始,R重复从上一个M(如果当前位 ...
随机推荐
- 花了5天时间,终于解决了一个bug,心情非常愉快,憋了这么久,不吐不快
http://www.cnweblog.com/fly2700/archive/2011/12/06/318916.html (转载) 花了5天时间,终于解决了一个bug,心情非常愉快,憋了这么久,不 ...
- html5--3.21 课程小结与其他新增元素
html5--3.21 课程小结与其他新增元素 学习要点 了解新增的input属性pattern 其他几个新增元素(非表单中元素,但是也放在这里讲解) 新增的input属性pattern:设定输入类型 ...
- 通过Chrome浏览器进行android调试/Remote Debugging on Android with Chrome
The way your web content behaves on mobile can be dramatically different from the desktop experience ...
- caffe参数详解
转载自:https://blog.csdn.net/qq_14845119/article/details/54929389 solver.prototxt net:训练预测的网络描述文件,trai ...
- Git 常用命令学习
本文转载自:https://buptldy.github.io/2016/03/02/2016-03-02-Git%20Cheat%20Sheet/ 文章 创建版本库 初始化一个Git仓库,使用git ...
- 快速沃尔什变换(FWT)学习笔记 + 洛谷P4717 [模板]
FWT求解的是一类问题:\( a[i] = \sum\limits_{j\bigoplus k=i}^{} b[j]*c[k] \) 其中,\( \bigoplus \) 可以是 or,and,xor ...
- 解决向github提交代码不用输入帐号密码
解决方案:方案一: 在你的用户目录下新建一个文本文件.git-credentials Windows:C:/Users/username Mac OS X: /Users/username Linux ...
- Android四种启动模式
四种启动模式 standard(默认) singleTop singleTast singleInstance standard(默认) 系统默认的启动模式. Android是使用返回栈来管理活动的, ...
- 转:Ubuntu12.04编译VLC,在linux上运行
Ubuntu12.04编译vlc2.1.0 1.编译环境 VM8.0.1 # gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAP ...
- many-to-one 配置问题
需要引入org.hibernate.annotations.NotFound,当预期的被关联的元素不在数据库(关乎关联列的错误id)时,致使Hibernate无法解决关联性问题时,Hibernate就 ...