(あとで)
↓あとで (accepted in practice)
#define INF (1<<30) int dp[2][1010]; int main() { ll H,W,X,Y; while(cin>>H>>W>>X>>Y) { REP(col, 2) REP(x, 1010) dp[col][x]=INF; VVI co(2, VI(W)); REP(i, H) { string s; cin>>s; REP(x, s.size()) co[0][x]+=s[x]=='.', co[1][x]+=s[x]!='.'; } REP(x, W) { REP(col, 2) { RANGE(i, X, Y+1) { int v = 0; if(x-i>=0) v += dp[1-col][x-i]; if(x-i+1>=0) { RANGE(j, x-i+1, x+1) v += co[col][j]; dp[col][x] = min(dp[col][x], v); } } } } cout<<min(dp[0][W-1], dp[1][W-1])<<endl; } return 0; }