涂色paint BZOJ
来源:互联网 发布:晨曦是什么软件 编辑:程序博客网 时间:2024/06/05 03:19
题目传送门
思路:一个区间DP的模版题,dp[i][j]代表字符串从i到j最少需要多少次染色,然后就是区间DP了。
#include <algorithm>#include <cmath>#include <cstdio>#include <cstring>#include <iostream>#include <list>#include <map>#include <queue>#include <set>#include <stack>#include <string>#include <vector>#define MAXN 2010#define MAXE 40#define INF 1e9#define MOD 100003#define LL long long#define ULL unsigned long long#define pi 3.14159using namespace std;string str;int dp[MAXN][MAXN];int main() { std::ios::sync_with_stdio(false); cin >> str; memset(dp, 0, sizeof(dp)); for (int i = 1; i <= str.length(); ++i) dp[i][i] = 1; for (int i = 1; i <= str.length(); ++i) { for (int j = 1; j + i <= str.length(); ++j) { int pos = i + j; dp[j][pos] = INF; if (str[j - 1] == str[pos - 1]) { if (i == 1) { dp[j][pos] = 1; } else { dp[j][pos] = dp[j][pos - 1]; } } else { for (int k = j; k < pos; ++k) { dp[j][pos] = min(dp[j][pos], dp[j][k] + dp[k + 1][pos]); } } } } cout << dp[1][str.length()] << endl; return 0;}
阅读全文
0 0
- BZOJ 1260涂色 paint
- 涂色paint BZOJ
- bzoj 1260: [CQOI2007]涂色paint
- BZOJ 1260: [CQOI2007]涂色paint
- bzoj 1260: [CQOI2007]涂色paint
- BZOJ 1260 CQOI2007 涂色paint 动态规划
- 【BZOJ】【P1260】【CQOI2007】【涂色paint】【题解】【dp】
- 【DP】BZOJ 1260: [CQOI2007]涂色paint
- 【BZOJ】1260: [CQOI2007]涂色paint 区间dp
- BZOJ 1260: [CQOI2007]涂色paint 区间DP
- [BZOJ 1260] CQOI 2007 涂色paint · 动态规划
- bzoj 1260: [CQOI2007]涂色paint 区间动态规划
- BZOJ 1260 [CQOI2007]涂色paint 记忆化搜索/dp
- bzoj 1260: [CQOI2007]涂色paint(区间DP)
- 【bzoj1260】 [CQOI2007]涂色paint
- Paint Fence 栅栏涂色
- BZOJ1260: [CQOI2007]涂色paint
- bzoj1260 [CQOI2007]涂色paint
- c语言指针例题解答
- centos 7 配置IP与虚拟机网络排查
- ionic 3.0懒加载机制 实现过程
- Javascript--Event Loops
- Javascript函数深入掌握
- 涂色paint BZOJ
- 洛谷P1547 Out of Hay
- NO.2 Spring MVC CRUD起步
- tensorflow+图像分类使用的一些错误
- Expect工具的安装及使用方法
- DOM数据绑定
- 无法表示的数 51Nod
- STL算法——accumulate
- HashMap