标签:fine false size min max mes tps 区间 targe
[题目链接]
https://www.lydsy.com/JudgeOnline/problem.php?id=1090
[算法]
区间DP
[代码]
#include<bits/stdc++.h> using namespace std; #define MAXN 110 int len; int f[MAXN][MAXN]; char s[MAXN]; inline int calc(int x) { int ret = 0; while (x) { ret++; x /= 10; } return ret; } inline bool check(int l,int r,int pl,int pr) { int i; if ((r - l + 1) % (pr - pl + 1) != 0) return false; for (i = l; i <= r; i++) { if (s[i] != s[(i - l) % (pr - pl + 1) + pl]) return false; } return true; } inline int dp(int l,int r) { int i; if (l == r) return f[l][r] = 1; if (f[l][r] != -1) return f[l][r]; f[l][r] = r - l + 1; for (i = l; i < r; i++) { f[l][r] = min(f[l][r],dp(l,i) + dp(i + 1,r)); if (check(i + 1,r,l,i)) f[l][r] = min(f[l][r],dp(l,i) + calc((r - i) / (i - l + 1) + 1) + 2); } return f[l][r]; } int main() { scanf("%s",s + 1); len = strlen(s + 1); memset(f,255,sizeof(f)); printf("%d\n",dp(1,len)); return 0; }
标签:fine false size min max mes tps 区间 targe
原文地址:https://www.cnblogs.com/evenbao/p/9371120.html