首先先预处理每行刷1~m次最多能正确涂出多少格

然后把每行涂色看做一个物品,当重量为j(这行涂了j次),价值为对应能正确涂出的格子数;

总重量为k,然后做分组背包即可

 1 var f:array[0..60,0..60,0..60] of longint;
 2     sum:array[0..60,0..60] of longint;
 3     dp:array[0..60,0..3000] of longint;
 4     t,x,p,n,m,k,l,i,j:longint;
 5     s:string;
 6 
 7 function max(a,b:longint):longint;
 8   begin
 9     if a>b then exit(a) else exit(b);
10   end;
11 
12 begin
13   readln(n,m,t);
14   for i:=1 to n do
15   begin
16     readln(s);
17     l:=length(s);
18     for j:=1 to l do
19     begin
20       x:=ord(s[j])-48;
21       sum[i,j]:=sum[i,j-1]+x;
22     end;
23   end;
24   for i:=1 to n do
25   begin
26     for j:=1 to m do
27     begin
28       f[i,j,0]:=0;
29       for k:=1 to j do
30       begin
31         for l:=j-1 downto 0 do
32         begin
33           p:=sum[i,j]-sum[i,l];
34           f[i,j,k]:=max(f[i,j,k],f[i,l,k-1]+max(p,j-l-p));
35         end;
36       end;
37     end;
38   end;
39   for i:=1 to n do
40   begin
41     for j:=t downto 0 do
42     begin
43       for k:=0 to m do
44         if j-k>=0 then dp[i,j]:=max(dp[i,j],dp[i-1,j-k]+f[i,m,k])
45         else break;
46     end;
47   end;
48   writeln(dp[i,t]);
49 end.
View Code

 

posted on 2014-07-19 20:09  acphile  阅读(122)  评论(0编辑  收藏  举报