JZOJ 1035. [painters] SCOI2009

topic

Description

windy there are N pieces of wood that needs to be whitewashed.
Each plank is divided into M grid.
Each grid to be painted red or blue.
windy each painting, on a board can only select a contiguous lattice, and then coated with a color.
Each grid can only be whitewashed once.
If you can only paint T windy times, right up to him how much paint the grid?
If a grid is not paint or paint the wrong color, wrong even paint.
 

Input

The first line contains three integers, NMT.
Then there are N rows, each row of a string of length M, '0' represents red, '1' represents blue.

Output

Output An integer representing the number of grid up to the right of the paint.
 

Sample Input

3 6 3
111111
000000
001100

Sample Output

16
 

Data Constraint

 
 

Hint

100% data satisfies 1 <= N, M <= 50; 0 <= T <= 2500.

 

analysis

 

  • Set F [i] [j] [0/1] times as the front brush j i lattice, the current i-th color cell is 0/1
  • Clear
    r=((i-1)*m)+j;
    			if (j!=1)
    			f[r][k][0]=max(f[r-1][k][0],f[r-1][k-1][1]), f[r][k][1]=max(f[r-1][k][1],f[r-1][k-1][0]); else f[r][k][0]=max(f[r-1][k-1][0],f[r-1][k-1][1]), f[r][k][1]=max(f[r-1][k-1][1],f[r-1][k-1][0]); if (s[j-1]=='0') f[r][k][0]++; else f[r][k][1]++;

 

Code

 1 #include <iostream>
 2 using namespace std;
 3 int f[2501][2501][2],r;  
 4 int main()
 5 {
 6     int n,m,t;
 7     cin>>n>>m>>t;
 8     string s;
 9     for (int i=1;i<=n;i++)
10     {
11         cin>>s;
12         for (int j=1;j<=m;j++)
13           for (int k=1;k<=t;k++)
14         {
15             r=((i-1)*m)+j;
16             if (j!=1)
17             f[r][k][0]=max(f[r-1][k][0],f[r-1][k-1][1]),
18             f[r][k][1]=max(f[r-1][k][1],f[r-1][k-1][0]);
19             else 
20             f[r][k][0]=max(f[r-1][k-1][0],f[r-1][k-1][1]),
21             f[r][k][1]=max(f[r-1][k-1][1],f[r-1][k-1][0]);
22             if (s[j-1]=='0') f[r][k][0]++;
23             else f[r][k][1]++;
24             
25         }
26     }
27     cout<<max(f[r][t][1],f[r][t][0]);
28 } 

 

Guess you like

Origin www.cnblogs.com/zjzjzj/p/11330409.html