1090: [SCOI2003]字符串折叠 区间DP
来源:互联网 发布:python list 迭代器 编辑:程序博客网 时间:2024/06/18 17:41
好久没做区间DP啦……
我们可以用f[l][r]表示l->r的最小折叠长度,那么f[l][r]可以由f[l][i],f[i+1][r]转移而来,每次判断一下是否有折叠部分,如果有就暴力判断更新答案。记忆化搜索解决较方便。
#include<iostream>#include<cstdio>#include<cstring>using namespace std;char s[105];int f[105][105];bool judge(int ll,int lr,int rl,int rr){ if ((rr-rl+1)%(lr-ll+1)!=0) return 0; for (int i=rl;i<=rr;i++) if (s[i]!=s[(i-rl)%(lr-ll+1)+ll]) return 0; return 1;}int num(int x){ int t=0; while (x) x/=10,t++; return t;}int dp(int l,int r){ if (l==r) return 1; if (f[l][r]) return f[l][r]; int t=r-l+1; for (int i=l;i<r;i++) { t=min(t,dp(l,i)+dp(i+1,r)); if (judge(l,i,i+1,r)) t=min(t,dp(l,i)+2+num((r-i)/(i-l+1)+1)); } f[l][r]=t; return f[l][r];} int main(){ scanf("%s",s); printf("%d",dp(0,strlen(s)-1)); return 0;}
0 0
- BZOJ 1090 [SCOI2003]字符串折叠 区间DP
- 1090: [SCOI2003]字符串折叠 区间DP
- 【bzoj 1090】[SCOI2003]字符串折叠 区间dp
- [BZOJ]1090: [SCOI2003]字符串折叠 区间DP
- 【BZOJ1090】[SCOI2003]字符串折叠【区间DP】
- BZOJ1090: [SCOI2003]字符串折叠 区间DP
- 【BZOJ1090】【SCOI2003】字符串折叠 {区间dp}
- BZOJ1090(SCOI2003)[字符串折叠]--区间DP
- 1090: [SCOI2003]字符串折叠 (区间动态规划)
- 1090: [SCOI2003]字符串折叠
- bzoj1090: [SCOI2003]字符串折叠 dp
- [DP] BZOJ1090: [SCOI2003]字符串折叠
- BZOJ 1090: [SCOI2003]字符串折叠 区间动归
- BZOJ 1090: [SCOI2003]字符串折叠
- 【BZOJ 1090】 [SCOI2003]字符串折叠
- bzoj 1090 [SCOI2003]字符串折叠
- 【BZOJ 1090】[SCOI2003]字符串折叠
- BZOJ系列1090《[SCOI2003]字符串折叠》题解
- 指针的自加自减运算(++,--)
- 2134: 单选错位|概率与期望
- Java 集合:Map 系列(HashMap,HashTable)
- ActionBar使用要点
- initrd原理
- 1090: [SCOI2003]字符串折叠 区间DP
- Codeforces Round #339 (Div. 2) (A,B,C,D)
- thinkphp中的M方法和D方法
- arm汇编 EXPORT 或 GLOBAL
- Android开发Tips(2)
- mycat 测试
- 设计模式-----桥接模式(Bridge Pattern)
- IplImage\Mat\CvMat像素处理
- onscroll事件揭秘&&模拟下拉滚动条效果