标签:
/* Author: JDD PROG: lightoj1422 Halloween Costumes DATE: 2015.10.8 */ #include <cstdio> #define REP(i, s, n) for(int i = s; i <= n; i ++) #define REP_(i, s, n) for(int i = n; i >= s; i --) #define MAX_N 105 using namespace std; int read() { char c = getchar(); while(!(c >= ‘0‘ && c <= ‘9‘)) c = getchar(); int ret = 0; while(c >= ‘0‘ && c <= ‘9‘) ret = ret * 10 + c - ‘0‘, c = getchar(); return ret; } int n, a[MAX_N], F[MAX_N][MAX_N]; void init() { n = read(); REP(i, 1, n) a[i] = read(); } #define min(a, b) (a < b ? a : b) void doit() { REP(i, 1, n) REP(j, 1, n){ if(i == j) F[i][j] = 1; else F[i][j] = 0; } REP(i, 1, n) REP(j, i + 1, n){ F[i][j] = F[i][j - 1] + 1; REP(k, i, j - 1) if(a[j] == a[k]) F[i][j] = min(F[i][j], F[i][k] + F[k + 1][j - 1]); } printf("%d\n", F[1][n]); } int main() { int T; scanf("%d", &T); REP(i, 1, T){ init(); printf("Case %d: ", i); doit(); } }
LigntOj1422 Halloween Custumes
标签:
原文地址:http://www.cnblogs.com/ALXPCUN/p/4862136.html