For a given n * m board, each vertex needs to be flushed into one or two colors. Each vertex can only be flushed for a row in a row, and only one vertex can be flushed once, find the maximum number of T-paint brush points
First, the processing order for each line is f [I] [J]. To use the I brush to brush the first J grids, the maximum number of vertices can be brushed. the number of points and then group the backpack.
# Include <cstdio> # include <cstring> # include <iostream> # include <algorithm> # define M 60 using namespace STD; int n, m, T, f [m] [m]; // F [I] [J] indicates the maximum number of grids that can be flushed out with the I brush. // F [I] [J] = max {f [I-1] [k] + max (CNT [0], CNT [1])} // (I-1 <= k <= J-1) Char s [m]; int A [m] [m]; // A [I] [J] indicates the maximum value of void dp (int pos) {int I, j, k; memset (F, 0xef, sizeof F); F [0] [0] = 0; for (I = 1; I <= m; I ++) {for (j = I; j <= m; j ++) {int CNT [2] = {0}; For (k = J-1; k> = I-1; k --) {CNT [s [k + 1]-'0'] ++; F [I] [J] = max (F [I] [J], f [I-1] [k] + max (CNT [0], CNT [1]) ;}}for (I = 1; I <= m; I ++) A [POS] [I] = f [I] [m];} int packet_backpack () {int I, J, K; static int G [m] [M * m]; memset (G, 0xef, sizeof g); G [0] [0] = 0; for (I = 1; I <= N; I ++) for (j = 0; j <= m; j ++) for (k = T; k> = J; k --) G [I] [k] = max (G [I] [K], G [I-1] [k-J] + A [I] [J]); return G [N] [T];} int main () {int I; CIN> N> m> T; for (I = 1; I <= N; I ++) {scanf ("% s", S + 1); DP (I) ;}cout <packet_backpack () <Endl ;}
Bzoj 1296 scoi2009 dynamic Planner