标签:
#include<iostream> #include<cstdio> #include<cstring> using namespace std ; const int maxn = 1010; const int inf = 0x3f3f3f3f ; int dp[maxn][2] ; char str[maxn][maxn] ; int num[maxn]; int sum_b[maxn]; int sum_w[maxn]; int main() { // freopen("in.txt","r",stdin); int r , c , x , y; //while(~scanf("%d%d%d%d" ,&r , &c ,&x ,&y)) // { scanf("%d%d%d%d" ,&r , &c ,&x ,&y); for(int i = 1;i <= r ;i++) scanf("%s" ,&str[i][1]) ; memset(num , 0 , sizeof(num)) ; memset(sum_b , 0 ,sizeof(sum_b)) ; memset(sum_w , 0 ,sizeof(sum_w)); for(int j = 1;j <= c ;j++) { for(int i = 1;i <= r;i++) if(str[i][j] == ‘.‘) num[j]++; } for(int j = 1; j <= c;j++) { sum_b[j]=(sum_b[j-1]+num[j]) ; sum_w[j] = (sum_w[j-1]+ r-num[j]); } //for(int i = 1;i <= c;i++) //printf("%d %d\n",sum_w[i],sum_b[i]) ; for(int i = 1;i <= c;i++) dp[i][0] = dp[i][1] = inf ; dp[0][0] = dp[0][1] =0 ; for(int i = 1;i <= c;i++) { for(int j = x;j <= y && j <= i ;j++) dp[i][1] = min(dp[i-j][0]+sum_w[i] -sum_w[i - j] ,dp[i][1]); for(int j = x;j <= y && j <= i ;j++) dp[i][0] = min(dp[i-j][1] + sum_b[i] - sum_b[i -j],dp[i][0]) ; } printf("%d\n" ,min(dp[c][0] ,dp[c][1])) ; //} }
Codeforces Round #139 (Div. 2)C Barcode DP
标签:
原文地址:http://blog.csdn.net/cq_pf/article/details/45082029