Topic Links:
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=27130
Simulating the whole process is a stack of operations it's hard to think of the interval $dp$
But think about it. You might find that for a stack of elements there is obviously a stack of elements behind it.
Then there are a bunch of elements in the stack after the stack $......$
We can then divide the interval according to the stack bottom element and then once again become the top element of the stack.
$ ($ in fact that is the test instructions to put on a piece of clothing and once again make it the outermost piece $) $
So the transfer equation can be written as
$f [I][j] = F[i + 1][j] + 1 ($ $i$ Party costume not used multiple times $) $
$f [I][j] = min (f[i][k-1] + f[k + 1][j]) ($ $i$ Party costumes used in the first $k$ of the party are reused $) $
1#include <cstdio>2#include <cstring>3#include <cmath>4#include <algorithm>5 using namespacestd;6 intc[ the], f[ the][ the];7 intt, N;8 intMain ()9 {Tenscanf"%d", &t); One for(intCA =1; CA <= T; ++CA) A { -scanf"%d", &n); - for(inti =1; I <= N; ++i) thescanf"%d", &c[i]); - for(inti =1; I <= N; ++i) -F[i][i] =1; - for(intLen =1; Len <= N; ++len) + for(inti =1; i + Len-1<= N; ++i) - { + intj = i + len-1; AF[I][J] = f[i +1][J] +1; at for(intK = i +1; K <= J; ++k) - if(C[i] = =C[k]) -F[i][j] = min (f[i][j], f[i][k-1] + f[k +1][j]); - } -printf"Case %d:%d\n", CA, f[1][n]); - } in return 0; -}
Lightoj 1422 Halloween Costumes