【bzoj1090】[SCOI2003]字符串折叠
来源:互联网 发布:微信刷赞软件破解版 编辑:程序博客网 时间:2024/05/22 14:02
1090: [SCOI2003]字符串折叠
Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1652 Solved: 1093
[Submit][Status][Discuss]
Description
折叠的定义如下: 1. 一个字符串可以看成它自身的折叠。记作S S 2. X(S)是X(X>1)个S连接在一起的串的折叠。记作X(S) SSSS…S(X个S)。 3. 如果A A’, BB’,则AB A’B’ 例如,因为3(A) = AAA, 2(B) = BB,所以3(A)C2(B) AAACBB,而2(3(A)C)2(B)AAACAAACBB 给一个字符串,求它的最短折叠。例如AAAAAAAAAABABABCCD的最短折叠为:9(A)3(AB)CCD。
Input
仅一行,即字符串S,长度保证不超过100。
Output
仅一行,即最短的折叠长度。
Sample Input
NEERCYESYESYESNEERCYESYESYES
Sample Output
14
HINT
一个最短的折叠为:2(NEERC3(YES))
Source
#include<cstdio>#include<cmath>#include<queue>#include<stack>#include<vector>#include<algorithm>#include<cstring>using namespace std;typedef long long LL;const int INF = 2147483647;const int maxn = 110;char s[maxn];int n,f[maxn][maxn],maxlen[maxn][maxn];inline LL getint(){LL ret = 0,f = 1;char c = getchar();while (c < '0' || c > '9'){if (c == '-') f = -1;c = getchar();}while (c >= '0' && c <= '9')ret = ret * 10 + c - '0',c = getchar();return ret * f;}inline int cal(int x){int cnt = 0;while (x) cnt++ , x /= 10;return cnt;}int main(){scanf("%s",s + 1);n = strlen(s + 1);for (int i = 1; i <= n; i++)for (int j = i; j <= n; j++)for (int k = 1; k <= n; k++){bool tmp = 0;if (i + k * (j - i + 1) > n) break;for (int l = 0; l <= j - i; l++)if (s[i + l] != s[i + k * (j - i + 1) + l]) {tmp = 1;break;}if (tmp) break;maxlen[i][j] = k;}for (int i = 1; i <= n; i++) f[i][i] = 1;for (int len = 1; len <= n; len++)for (int i = 1; i <= n; i++){int j = i + len;int test;if (i == 6 && j == 14)test = 1;f[i][j] = INF;for (int k = i; k < j; k++)f[i][j] = min(f[i][j],f[i][k] + f[k + 1][j]);for (int k = i; k < j; k++){if ((j - i + 1) % (k - i + 1) != 0) continue;if (maxlen[i][k] + 1 >= (j - i + 1) / (k - i + 1))f[i][j] = min(f[i][j],f[i][k] + 2 + cal((j - i + 1) / (k - i + 1)));}}printf("%d",f[1][n]);return 0;}
阅读全文
0 0
- 【BZOJ1090 || SCOI2003】字符串折叠
- bzoj1090: [SCOI2003]字符串折叠
- bzoj1090[SCOI2003]字符串折叠
- bzoj1090 [SCOI2003]字符串折叠
- bzoj1090 [SCOI2003]字符串折叠
- BZOJ1090 [SCOI2003]字符串折叠
- 【bzoj1090】[SCOI2003]字符串折叠
- bzoj1090: [SCOI2003]字符串折叠 dp
- [DP] BZOJ1090: [SCOI2003]字符串折叠
- 【BZOJ1090】[SCOI2003]字符串折叠【区间DP】
- BZOJ1090: [SCOI2003]字符串折叠 区间DP
- 【BZOJ1090】【SCOI2003】字符串折叠 {区间dp}
- BZOJ1090(SCOI2003)[字符串折叠]--区间DP
- 【题解】[scoi2003]字符串折叠
- 1090: [SCOI2003]字符串折叠
- BZOJ 1090: [SCOI2003]字符串折叠
- 【BZOJ 1090】 [SCOI2003]字符串折叠
- bzoj 1090 [SCOI2003]字符串折叠
- 资源
- Unit8
- string
- TMMi如何促进软件测试过程的改进
- 用程序来控制一个网页,实现自动输入等操作
- 【bzoj1090】[SCOI2003]字符串折叠
- 最短路—Floyd(QAQ)
- 如何搭建健身房教练私教器材设备微信公众号预约系统
- 将MongoDB的数据提取出来并转到MySQL遇到的问题
- centos7安装samba
- Oracle数据库之ROWID伪列
- mysql 提高查询效率的方法
- OpenCV编译,FFmpeg或ippicv下载不成功
- 利用Ansible部署运行Apache(http)的Docker容器