// 区间DP+next求循环节 uva 6876
// 题意:化简字符串 并表示出来
// 思路:dp[i][j]表示 i到j的最小长度
// 分成两部分 再求一个循环节 #include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define LL long long
typedef pair<int,int> pii;
const int inf = 0x3f3f3f3f;
const int MOD = ;
const int N = ;
const int maxx = ;
#define clc(a,b) memset(a,b,sizeof(a))
const double eps = 0.025;
void fre() {freopen("in.txt","r",stdin);}
void freout() {freopen("out.txt","w",stdout);}
inline int read() {int x=,f=;char ch=getchar();while(ch>''||ch<'') {if(ch=='-') f=-; ch=getchar();}while(ch>=''&&ch<='') {x=x*+ch-'';ch=getchar();}return x*f;} char s[N];
int dp[N][N];
int cas=;
int nextt[N]; int getnext(char *t,int len){
int i=,j=-;
// int len=strlen(t);
nextt[]=-;
while(i<len){
if(t[i]==t[j]||j==-){
i++;
j++;
nextt[i]=j;
}
else
j=nextt[j];
}
return len-nextt[len];
} int getbit(int x){
int cnt=;
while(x){
x/=;
cnt++;
}
return cnt;
}
void DP(){
int n=strlen(s+);
for(int i=;i<=n;i++) {
for(int j=i+;j<=n;j++)
dp[i][j]=;
dp[i][i]=;
}
for(int len=;len<=n;len++){
for(int l=;l+len-<=n;l++){
int r=l+len-;
for(int k=l;k<r;k++){
dp[l][r]=min(dp[l][k]+dp[k+][r],dp[l][r]);
}
int t=getnext(s+l,len);
if((len%t)==){
int tem=dp[l][l+t-];
if(t>) tem+=;
tem+=getbit(len/t);
dp[l][r]=min(dp[l][r],tem);
}
}
}
printf("Case %d: %d\n",cas++,dp[][n]);
}
int main(){
// fre();
while(~scanf("%s",s+)){
if(s[]=='') break;
DP();
}
return ;
}

区间DP+next求循环节 uva 6876的更多相关文章

  1. hdu 4291(矩阵+暴力求循环节)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4291 思路:首先保留求出循环节,然后就是矩阵求幂了. #include<iostream> ...

  2. hdu 3374 String Problem (字符串最小最大表示 + KMP求循环节)

    Problem - 3374   KMP求循环节. http://www.cnblogs.com/wuyiqi/archive/2012/01/06/2314078.html   循环节推导的证明相当 ...

  3. UVA 12012 Detection of Extraterrestrial(KMP求循环节)

    题目描述 E.T. Inc. employs Maryanna as alien signal researcher. To identify possible alien signals and b ...

  4. hdu 4794 FIb求循环节

    很容易看出来这道题是求模n意义下fib数列的最小循环节 对于fib数列的最小循环节的求法,我们可以这样: 1.令n=p1^m1 * p2^m2 * p3^m3…… 2.分别计算fib数列在模p1^m1 ...

  5. Cyclic Nacklace - HDU 3746(next求循环节)

    题目大意:给你一些串,问如果想让这个串里面的循环节至少循环两次,需要添加几个字符(只能在最前面或者最后面添加).比如ababc 需要添加5个就是添加ababc. 分析:其实字符串的长度len-next ...

  6. 51nod 1126 求递推序列的第N项 思路:递推模拟,求循环节。详细注释

    题目: 看起来比较难,范围10^9 O(n)都过不了,但是仅仅是看起来.(虽然我WA了7次 TLE了3次,被自己蠢哭) 我们观察到 0 <= f[i] <= 6 就简单了,就像小学初中学的 ...

  7. HDU 4259 - Double Dealing(求循环节)

    首先将扑克牌进行一次置换,然后分解出所有的循环节,所有循环节的扑克牌个数的最小公倍数即为答案 #include <stdio.h> #include <string.h> #i ...

  8. 历届试题 小数第n位 (求循环节)

    只要被除数出现重复,就表明循环节出现了.即使商不是循环小数,也可以补0作为循环节,这样就可以统一处理了. AC代码 #include <stdio.h> #include <vect ...

  9. 【HDU 3746】Simpsons’ Hidden Talents(KMP求循环节)

    求next数组,(一般有两种,求循环节用的见代码)求出循环节的长度. #include <cstdio> #define N 100005 int n,next[N]; char s[N] ...

随机推荐

  1. JTable指定单元格加控件

    原文链接:http://blog.csdn.net/transit136/article/details/2133638 JTable可以给表格的某一列加入控件,下面方法可以实现   try{   T ...

  2. Java 反编译工具几枚(class转java)

    1.Java Decompiler Yet another fast Java decompiler. 下载地址:http://jd.benow.ca/#jd-gui-download 一款非常简洁的 ...

  3. 224. Basic Calculator

    题目: Implement a basic calculator to evaluate a simple expression string. The expression string may c ...

  4. Nmap扫描原理与用法

    Nmap扫描原理与用法 1     Nmap介绍 Nmap扫描原理与用法PDF:下载地址 Nmap是一款开源免费的网络发现(Network Discovery)和安全审计(Security Audit ...

  5. 计算机视觉和人工智能的状态:我们已经走得很远了 The state of Computer Vision and AI: we are really, really far away.

    The picture above is funny. But for me it is also one of those examples that make me sad about the o ...

  6. Android权限安全(8)ContentProvider基于URI的安全

    一.provider可以通过binder得到客户的uid,然后进程权限检查. 二,provider临时权限 场景:  Email的内容在provider中提供,Email的客户端可读基其内容,现在一封 ...

  7. C#使用sharppcap实现网络抓包-----2

    虽然网上已经有了SharpSniffer 这一个SharpSniffer还是原创的无他,唯为学习工程文件下载:SharpSniffer.rar 1.创建套接字2.绑定到本机3.设置IOControl4 ...

  8. Generic Data Access Layer泛型的数据访问层

    http://www.codeproject.com/Articles/630277/Generic-Data-Access-Layer-GDA-Part-I http://www.codeproje ...

  9. [Codeforces677B]Vanya and Food Processor(模拟,数学)

    题目链接:http://codeforces.com/contest/677/problem/B 题意:n个土豆,每个土豆高ai.现在有个加工机,最高能放h,每次能加工k.问需要多少次才能把土豆全加工 ...

  10. C++ STL之迭代器注意事项

    1.两个迭代器组成的区间是前闭后开的 2.如果迭代器的有效性,如果迭代器所指向的元素已经被删除,那么迭代器会失效 http://blog.csdn.net/hsujouchen/article/det ...