标签:c++ using col pen paint can pre 位长 rip
链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1260
Time Limit: 30 Sec Memory Limit: 64 MB40%的数据满足:1<=n<=10
100%的数据满足:1<=n<=50
题解:
#include <bits/stdc++.h> #define ll long long using namespace std; const int M = 55; int dp[M][M]; char col[M]; int main() { scanf("%s", col); int n = strlen(col); memset(dp, 127, sizeof(dp)); for(int i = 1; i <= n; i++)dp[i][i] = 1; for(int len = 2; len <= n; len++){ for(int i = 1; i <= n; i++){ int j = i + len - 1; if(j > n)break; if(col[i - 1] == col[j - 1]) dp[i][j] = min(dp[i + 1][j], min(dp[i][j - 1], dp[i + 1][j - 1] + 1)); else for(int k = i; k < j; k++) dp[i][j] = min(dp[i][k] + dp[k+1][j], dp[i][j]); } } printf("%d\n", dp[1][n]); return 0; }
最近心血来潮,有空就插点我喜欢的图吧
标签:c++ using col pen paint can pre 位长 rip
原文地址:https://www.cnblogs.com/EdSheeran/p/9460667.html