LightOJ 1044 - Palindrome Partitioning(dp)
来源:互联网 发布:淘宝定金尾款凑单 编辑:程序博客网 时间:2024/05/23 18:36
题目链接:LightOJ 1044 - Palindrome Partitioning
代码
#include <cstdio>#include <cstring>#include <queue>#include <vector>#include <algorithm>using namespace std;const int maxn = 1005;const int inf = 0x3f3f3f3f;typedef pair<int,int> pii;char S[maxn];int N, dp[maxn];vector<int> G[maxn];void init () { scanf("%s", S + 1); N = strlen(S + 1); for (int i = 0; i <= N; i++) G[i].clear(); queue<pii> que; for (int i = 1; i <= N; i++) que.push(make_pair(i, i)); for (int i = 1; i < N; i++) if (S[i] == S[i+1]) que.push(make_pair(i, i + 1)); while (!que.empty()) { int l = que.front().first; int r = que.front().second; que.pop(); G[l-1].push_back(r); l--, r++; if (l == 0 || r > N) continue; if (S[l] == S[r]) que.push(make_pair(l, r)); }}int solve () { memset(dp, inf, sizeof(dp)); dp[0] = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < G[i].size(); j++) dp[G[i][j]] = min(dp[G[i][j]], dp[i] + 1); } return dp[N];}int main () { int cas; scanf("%d", &cas); for (int kcas = 1; kcas <= cas; kcas++) { init(); printf("Case %d: %d\n", kcas, solve()); } return 0;}
0 0
- LightOJ 1044 - Palindrome Partitioning(dp)
- LightOJ 1044 - Palindrome Partitioning (区间dp)
- lightoj 1044 Palindrome Partitioning(dp)
- LightOJ - 1044 Palindrome Partitioning(DP)
- LightOJ 1044 - Palindrome Partitioning(DP)
- LightOJ 1044 - Palindrome Partitioning【dp】
- lightoj 1044 - Palindrome Partitioning DP优化DP
- lightoj 1044 - Palindrome Partitioning
- lightoj 1044 - Palindrome Partitioning
- Light OJ 1044 Palindrome Partitioning (hash+DP)
- 1044 - Palindrome Partitioning(记忆化DP)
- 131 Palindrome Partitioning(dp+dfs)
- 132. Palindrome Partitioning II(dp)
- Leetcode 132 - Palindrome Partitioning II(dp)
- 【DP】Palindrome Partitioning I
- 【DP】Palindrome Partitioning II
- DP Palindrome Partitioning II
- [leetcode][DP] Palindrome Partitioning II
- brutish mine 攻略补充
- LightOJ 1038 - Race to 1 Again(dp)
- Swift(十五、构造过程(2)及析构过程)
- spring整合hibernate和spring MVC
- 多备份为国产大飞机助推者恒润科技构建IT保护平台
- LightOJ 1044 - Palindrome Partitioning(dp)
- LightOJ 1047 - Neighbor House(dp)
- 严重: Context [] startup failed due to previous errors
- java设置客户端缓存控制:session保留时间
- LightOJ 1050 - Marbles(dp)
- ios 后台录音权限设置
- LightOJ 1051 - Good or Bad(dp)
- SQL去空格
- LightOJ 1057 - Collecting Gold(dp)