比赛 2025.10.18 评测结果 AAAAAAAAAA
题目名称 01数列 最终得分 100
用户昵称 梦那边的美好TT 运行时间 0.059 s
代码语言 C++ 内存使用 6.56 MiB
提交时间 2025-10-18 09:48:24
显示代码纯文本
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll MOD =1e9 +7;
const int MAXN =1005;

ll pow2(ll x) {
	ll res =1, base =2;
	while (x) {
		if (x &1) res = res * base % MOD;
		base = base * base % MOD;
		x >>=1;
	}
	return res;
}

ll comb[MAXN][MAXN];

void f(int n) {
	for (int i =0; i <= n; i++) {
		comb[i][0] =1;
		for (int j =1; j <= i; j++) {
			comb[i][j] = (comb[i-1][j-1] + comb[i-1][j]) % MOD;
		}
	}
}

int main() {
	freopen("01.in","r",stdin);
	freopen("01.out","w",stdout);
	int n;
	cin >> n;
	vector<int> b(n);
	for (int i =0; i < n; i++) cin >> b[i];
	f(n);
	int cnt0 = count(b.begin(), b.end(),0);
	int cnt1 = n - cnt0;
	ll ans =0;
	for (int t =0; t <= n; t++) {
		ll exponent =1LL * cnt0 * (n - t) +1LL * cnt1 * t;
		ll term = comb[n][t] * pow2(exponent) % MOD;
		ans = (ans + term) % MOD;
	}
	cout << ans << endl;
	return 0;
}