提交时间:2023-01-20 16:53:49
运行 ID: 67876
#include <bits/stdc++.h> using namespace std; int read() { int x = 0, w = 1; char c = 0; while (c < '0' || c > '9') { if (c == '-') w = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = (x << 3) + (x << 1) + (c - '0'); c = getchar(); } return x * w; } const int N = 1e5 + 5, P = 1e9 + 7; void exgcd(int a, int b, int& x, int& y) { if (b == 0) { x = 1, y = 0; return; } exgcd(b, a % b, y, x); y -= a / b * x; } inline int qpow(long long a, int b) { int ans = 1; a = (a % P + P) % P; for (; b; b >>= 1) { if (b & 1) ans = (a * ans) % P; a = (a * a) % P; } return ans; } int fac[N], inv[N]; int wasteMaterial; int C[N]; int CalcC(int x, int y) { if (x == 0 || y == 0 || x - y == 0) return 1; return 1ll * fac[x] * (1ll * inv[y] * inv[x - y] % P) % P; } int main() { int n = read() - 1; fac[0] = 1; for (int i = 1; i <= n; i++) { fac[i] = (1ll * fac[i - 1] * i) % P; } exgcd(fac[n], P, inv[n], wasteMaterial); inv[n] = (inv[n] % P + P) % P; for (int i = n - 1; i >= 1; i--) { inv[i] = (1ll * inv[i + 1] * (i + 1)) % P; } for (int i = 0; i <= n; i++) { C[i] = CalcC(n, i); } int sum = 0; for (int i = 0; i <= n; i++) { char ch; scanf(" %c", &ch); if (ch == '0') sum = (sum + C[i]) % P; } int fm; exgcd(qpow(2, n), P, fm, wasteMaterial); fm = (fm % P + P) % P; printf("%lld\n", 1ll * sum * fm % P); return 0; }