Bzoj 1260 cqoi2007 color paint Dynamic Planning

Source: Internet
Author: User

Given a piece of wood board, each of the above positions has a color. Ask how many times the brush can reach this color sequence.

For dynamic planning, you can re-process it first (not necessary), so that f [I] [J] indicates the minimum number of times that J positions starting with I are flushed into the corresponding color sequence, the status transfer is as follows:

If s [I] = s [J] Then f [I] [J] = min (F [I-1] [J], F [I] [J-1]) combine I and the right half into a brush, or combine J and the left half into a brush.

If s [I]! = S [J], F [I] [J] = min {f [I] [k] + F [I + k] [J-K]}, where 1 <= k <j

Then I can solve the problem... Get a greedy error status transfer...

# Include <cstdio> # include <cstring> # include <iostream> # include <algorithm> # define M 60 using namespace STD; int N; char s [m]; int f [m] [m]; int main () {int I, j, k; scanf ("% s", S + 1); for (I = 1; s [I]; I ++) if (s [I]! = S [I-1]) s [+ + N] = s [I]; memset (F, 0x3f, sizeof F); for (I = 1; I <= N; I ++) f [I] [1] = 1; for (j = 2; j <= N; j ++) for (I = 1; I + J-1 <= N; I ++) {If (s [I] = s [I + J-1]) f [I] [J] = min (F [I + 1] [J], F [I] [J-1]); For (k = 1; k <J; k ++) f [I] [J] = min (F [I] [J], f [I] [k] + F [I + k] [J-K]);} cout <F [1] [N] <Endl ;}


Bzoj 1260 cqoi2007 color paint Dynamic Planning

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.