-
Notifications
You must be signed in to change notification settings - Fork 749
/
1. Barcode.cpp
52 lines (42 loc) · 1.06 KB
/
1. Barcode.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include<bits/stdc++.h>
using namespace std;
#define int long long
int help(int j,int last,int siz,vector<int>&v,int x,int y,int n,int dp[1001][1001][2]) {
if(j==v.size()&&siz<x) return INT_MAX;
if(j==v.size()) return 0;
if(siz>y) return INT_MAX;
if(dp[j][siz][last]!=-1)return dp[j][siz][last];
int black = v[j];
int white = n-v[j];
dp[j][siz][last] = INT_MAX;
if(siz==0) {
dp[j][siz][last]=min(white+help(j+1,1,1,v,x,y,n,dp),black+help(j+1,0,1,v,x,y,n,dp));
} else {
dp[j][siz][last] = min(dp[j][siz][last],(last==1?white:black)+help(j+1,last,siz+1,v,x,y,n,dp));
if(siz>=x)
{
dp[j][siz][last] = min(dp[j][siz][last],(last==1?black:white)+help(j+1,1-last,1,v,x,y,n,dp));
}
}
return dp[j][siz][last];
}
int32_t main() {
int n,m,x,y;
cin>>n>>m>>x>>y;
vector<int> v(m,0);
for(int i=0;i<n;i++) {
for(int j=0;j<m;j++) {
char c;
cin>>c;
if(c=='#') v[j]++;
}
}
int dp[1001][1001][2];
for(int i=0;i<1001;i++) {
for(int j=0;j<1001;j++) {
dp[i][j][0]=-1;
dp[i][j][1]=-1;
}
}
cout<<help(0,1,0,v,x,y,n,dp);
}