template <typename T, typename... Args> voiderr(istream_iterator<string> it, T a, Args... args){ cerr << *it << " = " << a << " "; err(++it, args...); }
constexprint MAXN = 1e5 + 5, MOD = 1e9 + 7;
int h, w, a, b, ans; int st[16];
voidSearch(int r, int c, int a, int b){ if (a < 0 || b < 0) return; if (r == h) { if (a || b) return; for (int i = 0; i < h; i++) if (st[i] != (1 << w) - 1) return; ans++; return; } if (st[r] == (1 << w) - 1) { Search(r + 1, 0, a, b); return; } if (c < w && (st[r] >> c) & 1) Search(r, c + 1, a, b);
if (b > 0) { int pre = st[r]; st[r] |= (1 << c); Search(r, c + 1, a, b - 1); st[r] = pre; }
if (a > 0 && c < w - 1 && !((st[r] >> (c + 1)) & 1)) { int pre = st[r]; st[r] |= (1 << c); st[r] |= (1 << (c + 1)); Search(r, c + 2, a - 1, b); st[r] = pre; }
if (a > 0 && r != h - 1 && !((st[r + 1] >> c) & 1)) { int pre1 = st[r], pre2 = st[r + 1]; st[r] |= (1 << c); st[r + 1] |= (1 << c); Search(r, c + 1, a - 1, b); st[r] = pre1; st[r + 1] = pre2; } }
signedmain(){ boost; cin >> h >> w >> a >> b; Search(0, 0, a, b); cout << ans << endl; return0; }
intrev(int x, int sz){ int ans = 0; for (int i = 0; i < sz; i++) if ((x >> i) & 1) ans |= (1 << (sz - i - 1)); return ans; }
int R[4000001]; voiddft(Complex a[], int sz, int type){ for (int i = 0; i < sz; i++) if (i < R[i]) swap(a[i], a[R[i]]); for (int m = 2; m <= sz; m <<= 1) { Complex wm(cos(2 * PI / m), type * sin(2 * PI / m)); for (int k = 0; k < sz; k += m) { Complex w(1); for (int j = 0; j < m / 2; j++) { Complex t = w * a[k + j + m / 2]; Complex u = a[k + j]; a[k + j] = u + t; a[k + j + m / 2] = u - t; w = w * wm; } } } }
intmain(){ char c[] = {'0', '1'}; string s, t; cin >> s >> t; int n = s.size(), m = t.size(); int N = n; expand(N); Complex a[N]; for (int i = 0; i < N; i++) R[i] = rev(i, log2(N)); int matched[n] = {0}; for (int type = 0; type < 2; type++) { int f[n] = {0}; for (int i = 0; i < m; i++) a[i].x = (t[i] == c[type]); for (int i = 0; i < n; i++) if (s[i] == c[type]) f[i] = 1; for (int i = 0; i < n; i++) a[i].y = f[n - i - 1]; dft(a, N, 1); for (int i = 0; i < N; i++) a[i] = a[i] * a[i]; dft(a, N, -1); for (int i = 0; i < n - m + 1; i++) matched[i] += int(a[i + m - 1].y / 2.0 / N + 0.5); for (int i = 0; i < N; i++) a[i].x = a[i].y = 0; } int ans = 1E9; for (int i = 0; i < n - m + 1; i++) ans = min(ans, m - matched[i]); cout << ans << endl; return0; }
namespace NTT { constexprint NR = 1 << 22, g = 3, gi = 332748118, mod = 998244353;
longlongqpow(longlong a, longlong b){ longlong res = 1; while (b) { if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1; } return res; }
int R[4000001]; voidinit(int& sz){ if (__builtin_popcount(sz) != 1) sz = 1 << (1 + (int)log2(sz)); for (int i = 0; i < sz; i++) R[i] = (R[i >> 1] >> 1) | ((i & 1) ? (sz >> 1) : 0); }
voiddft(longlong a[], int sz, int type){ for (int i = 0; i < sz; i++) if (i < R[i]) swap(a[i], a[R[i]]); for (int m = 2; m <= sz; m <<= 1) { longlong gn = qpow(type == 1 ? g : gi, (mod - 1) / m); // 单位原根 g_n for (int k = 0; k < sz; k += m) { longlongg0(1); for (int j = 0; j < m / 2; j++) { longlong t = g0 * a[k + j + m / 2] % mod; longlong u = a[k + j]; a[k + j] = (u + t) % mod; a[k + j + m / 2] = (u - t + mod) % mod; g0 = g0 * gn % mod; } } } if (type == -1) { longlong inv = qpow(sz, mod - 2); for (int i = 0; i < sz; i++) a[i] = a[i] * inv % mod; } } }
namespace Polynomial { usingnamespace NTT;
voidConvolution(int n, int m, int a[], int b[], int c[]){ // a[0, n] b[0, m] int N = n + m + 1; init(N); longlong f[N], g[N]; for (int i = 0; i < N; i++) f[i] = g[i] = 0; for (int i = 0; i <= n; i++) f[i] = a[i]; for (int i = 0; i <= m; i++) g[i] = b[i]; dft(f, N, 1), dft(g, N, 1); longlong res[N]; for (int i = 0; i < N; i++) res[i] = 0; for (int i = 0; i < N; i++) res[i] = f[i] * g[i] % mod; dft(res, N, -1); for (int i = 0; i <= n + m; i++) c[i] = res[i]; } };