【每日一题】涂色PAINT
[CQOI2007]涂色PAINT
https://ac.nowcoder.com/acm/problem/19909
题意:
思路:
#include <cstdio> #include <algorithm> #include <cstring> using namespace std; const int N = 55; char s[N]; int f[N][N]; int main(){ scanf("%s",s + 1); int n = strlen(s + 1); memset(f,0x3f,sizeof(f)); for(int i = 1;i <= n;i++){ f[i][i] = 1; } for(int len = 2;len <= n;len++){ for(int i = 1;i + len - 1 <= n;i++){ int j = i + len - 1; if(s[i] == s[j]) f[i][j] = min(f[i+1][j],f[i][j-1]); else{ for(int k = i;k < j;k++){ f[i][j] = min(f[i][j],f[i][k] + f[k+1][j]); } } } } printf("%d\n",f[1][n]); return 0; }
每日一题 文章被收录于专栏
每题一题题目