BZOJ 1090: [SCOI2003]字符串折叠|动态规划
2016-01-19 07:33
309 查看
F[i][j]表示区间i到j的最短折叠
转移时枚举区间中的点即可
转移时枚举区间中的点即可
#include<set> #include<map> #include<ctime> #include<queue> #include<cmath> #include<cstdio> #include<vector> #include<cstring> #include<cstdlib> #include<iostream> #include<algorithm> #define T 50005 using namespace std; char s[111]; int f[111][111],mark[111][111]; bool jud(int L,int x,int y,int R) { if((R-y+1)%(x-L+1)!=0)return 0; for(int i=y;i<=R;i++) { if(s[i]!=s[(i-y)%(x-L+1)+L]) return 0; } return 1; } int cal(int x) { int ans=0; for(;x;x/=10)ans++; return ans; } int F(int L,int R) { if(L==R)return 1; if(mark[L][R])return f[L][R]; mark[L][R]=1; f[L][R]=R-L+1; for(int i=L;i<R;i++) { f[L][R]=min(f[L][R],F(L,i)+F(i+1,R)); if(jud(L,i,i+1,R)) { f[L][R]=min(f[L][R],F(L,i)+2+cal((R-i)/(i-L+1)+1)); } } //cout << L <<" "<<R<<" " <<f[L][R]<<endl; return f[L][R]; } int main() { scanf("%s",s); cout<<F(0,strlen(s)-1); return 0; }
相关文章推荐
- C++动态规划之最长公子序列实例
- C++动态规划之背包问题解决方法
- C#使用动态规划解决0-1背包问题实例分析
- 动态规划
- C++ 动态规划
- DP(动态规划) 解游轮费用问题
- 动态规划的用法——01背包问题
- 动态规划的用法——01背包问题
- 《收集苹果》 动态规划入门
- 《DNA比对》蓝桥杯复赛试题
- 《背包问题》 动态规划
- 初学ACM - 半数集(Half Set)问题 NOJ 1010 / FOJ 1207
- 关于爬楼梯的动态规划算法
- 动态规划 --- hdu 1003 **
- DP问题各种模型的状态转移方程
- 0-1背包解题过程
- 背包问题
- USACO 3.2.2:Stringsobits
- 字符串编辑距离
- HDU ACM Step 2.2.2 Joseph(约瑟夫环问题)