Folding
题意:
给定一个串,求能化成的最短循环节串(把重复字符串转化成循环节形式)
分析:
不是太好想,如果让求最短长度还好,dp[i][j],表示区间[i,j]化成的最小长度,dp[i][j]=min(dp[i][k]+dp[k+1][j]),即可但现在要求这个串不知怎么做,想着串能不能跟着转移啊,就用 str[l][r]表示区间[l,r]能化成的最短串,接着就是想怎么跟着转移了,当枚举k时,求出使得最短的k,str[l][r]=str[l][k]+str[k+1][r],再判断是否能再次循环。
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
#define lson l,m,rt<<1
#define pi acos(-1.0)
#define rson m+1,r,rt<<11
#define All 1,N,1
#define read freopen("in.txt", "r", stdin)
const ll INFll = 0x3f3f3f3f3f3f3f3fLL;
const int INF= 0x7ffffff;
const int mod = ;
char s[];
string str[][];
int dp[][];
int len(int l,int r){
for(int i=;i<=(r-l+)/;++i){
if((r-l+)%i)continue;
int f=;
for(int j=l;j+i<=r;++j)
{
if(s[j]!=s[j+i]){
f=;
break;
}
}
if(f)return i;
}
return ;
}
int dfs(int l,int r){
if(dp[l][r]!=-)return dp[l][r];
if(l==r){
dp[l][r]=;
str[l][r]=s[l];
return ;
}
int minv=INF,pos;
for(int i=l;i<r;++i){
int tmp=dfs(l,i)+dfs(i+,r);
if(tmp<minv){
pos=i;
minv=tmp;
}
}
str[l][r]=str[l][pos]+str[pos+][r];
int c=len(l,r);
if(c){
int t=(r-l+)/c;
string s1="";
while(t){
s1+=(''+t%);
t/=;
}
reverse(s1.begin(),s1.end());
s1+="("+str[l][l+c-]+")";
if(s1.size()<minv)
{
minv=s1.size();
str[l][r]=s1;
}
}
return dp[l][r]=minv;
}
int main()
{
while(~scanf("%s",s)){
memset(dp,-,sizeof(dp));
int n=strlen(s);
dfs(,n-);
cout<<str[][n-]<<endl;
}
return ;
}
Folding的更多相关文章
- Codeforces Gym 100002 Problem F "Folding" 区间DP
Problem F "Folding" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/ ...
- eclipse 插件之Code Folding
功能: eclipse自带折叠包括方法, import, 注释等得折叠功能, code folding 插件对其增强. 1. 下载插件:( 也可以用link方式, 我的是link安装, jar包网上很 ...
- Android Folding View(折叠视图、控件)
版本号:1.0 日期:2014.4.21 版权:© 2014 kince 转载注明出处 非常早之前看过有人求助以下这个效果是怎样实现的, 也就是側滑菜单的一个折叠效果,事实上关于这个效果的实现,谷 ...
- Chrome Dev Tools: Code Folding in CSS and Javascript for improved code readiability
Note : Apply for google chrome canary. You can fold code blocks in CSS (and Sass) and javascript fil ...
- Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) E. Tree Folding 拓扑排序
E. Tree Folding 题目连接: http://codeforces.com/contest/765/problem/E Description Vanya wants to minimiz ...
- Eclipse折叠代码 coffee bytes code folding
提供一个插件下载地址,博客园的: http://files.cnblogs.com/wucg/com.cb.eclipse.folding_1.0.6.jar.zip 将下载的zip文件解压出来的j ...
- poj2176 Folding【区间DP】
Folding Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1841 Accepted: 642 Special ...
- Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) E. Tree Folding
地址:http://codeforces.com/contest/765/problem/E 题目: E. Tree Folding time limit per test 2 seconds mem ...
- UVA1630 Folding 区间DP
Folding Description Bill is trying to compactly represent sequences of capital alphabetic characte ...
- Ural 1238 Folding 题解
目录 Ural 1238 Folding 题解 题意 题解 程序 Ural 1238 Folding 题解 题意 定义折叠.展开为: 单个大写英文字母是一个折叠的串,把它展开后是它本身. 如果\(S\ ...
随机推荐
- Ubuntu 升级内核
1. 升级下 sudo apt-get update && sudo apt-get dist-upgrade && sudo apt-get autoremove 2 ...
- UML系列02之UML类图(1)
类图介绍 类图,是UML(统一建模语言)中用于描述"类"以及"类与类"之间关系的示意图.它形象的描述出了系统的结构,帮助人们理解系统.类图是在"所有的 ...
- 转载 a href=#与 a href=javascript:void(0) 的区别
a href="#"> 点击链接后,页面会向上滚到页首,# 默认锚点为 #TOP <a href="javascript:void(0)" onCl ...
- WEB前端介绍
1.WEB前端是神马 Web前端开发是从网页制作演变而来的,名称上有很明显的时代特征.在互联网的演化进程中,网页制作是Web1.0时代的产物,那时网站的主要内容都是静态的,用户使用网站的行为也以浏览为 ...
- C# 字符串计算表达式
C# 字符串计算表达式 string str="4+4+2.1"; 要的效果: double sum=4+4+2.1: 方案一: 动态计算表达式: 1 public class ...
- php常用代码(一)
1.连接MYSQL数据库代码 <?php $connec=mysql_connect("localhost","root","root" ...
- ubuntu samba服务器多用户配置【转】
转自:http://www.2cto.com/os/201204/127043.html ubuntu samba服务器多用户配置 在/home/下有多个用户目录A.B...,现通过samba共享 ...
- 2.cadence制板流程[原创]
1.元器件库(原理图库) 2.原理图 3.DRC检查 4.输出网表 5.PCB封装 6.板子边框 7.导入网表 8.设置约束规则 9.布局,布线,铺铜 10.DRC检查,出丝印,钻孔,出广汇
- poj -2010 Moo University - Financial Aid (优先队列)
http://poj.org/problem?id=2010 "Moo U"大学有一种非常严格的入学考试(CSAT) ,每头小牛都会有一个得分.然而,"Moo U&quo ...
- cocos2dx Android 环境搭建 以及 ndk调试
最近在学习cocos2dx,真的很强大,使我们更专注于游戏趣味,免去了繁琐的底层框架代码. cocos2dx的最强大之处当然在于跨平台.跨平台首选当然是Android,好记性不如烂笔头,记下本文分享给 ...