直接大力组合数显然是不可行的,此时,我们一般选择 dp。
考虑状压,设 为状态为 时的只考虑 PICK 的答案,这里的状态 是每个人是否决策完成,如 时, 表第二个人和第五个人完成了决策的只考虑 PICK 的答案。
剩余 BAN 和敌方情况显然为 。最终输出 。
考虑转移。初始 。
我们要使所有人 PICK 的不相同,看似很难。实则可以从小到大枚举每个英雄的编号,直接转移即可。注意转移要同时进行即要开一个临时数组以滚动。
时间复杂度 ,其中 ,,。
有任何问题可以私信。
code
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int cs = 531192758, mod = 1e9 + 7;
int dp[35], ndp[35];
signed main()
{
string s[6];
while(cin >> s[1] >> s[2] >> s[3] >> s[4] >> s[5])
{
memset(dp, 0, sizeof dp);
memset(ndp, 0, sizeof ndp);
dp[0] = 1;
for(int i = 0; i <= 99; i++)
{
for(int j = 0; j <= 31; j++) ndp[j] = dp[j];
for(int j = 0; j <= 31; j++)
{
for(int x = 0; x <= 4; x++)
{
if((j >> x & 1) && s[x + 1][i] == '1')
{
ndp[j] = (ndp[j] + dp[j ^ (1 << x)]) % mod;
}
}
}
for(int j = 0; j <= 31; j++) dp[j] = ndp[j];
}
cout << dp[31] * cs % mod << '\n';
}
}