5 friends play LOL together . Every one should BAN one character and PICK one character . The enemy should BAN 55 characters and PICK 55 characters . All these 2020 heroes must be different .
Every one can BAN any heroes by his personal washes . But he can only PICK heroes which he has bought .
Suppose the enemy can PICK or BAN any heroes. How many different ways are there satisfying the conditions?
For example , a valid way is :
Player 11 : picks hero 11, bans hero 22
Player 22 : picks hero 33, bans hero 44
Player 33 : picks hero 5, bans hero 66
Player 44 : picks hero 77, bans hero 88
Player 55 : picks hero 99, bans hero 1010
Enemies pick heroes 11,12,13,14,1511,12,13,14,15 , ban heroes 16,17,18,19,2016,17,18,19,20 .
Input
The input contains multiple test cases.(No more than 2020)
In each test case . there’s 55 strings S[1] \sim S[5]S[1]∼S[5] ,respectively whose lengths are 100100 , For the ii-th person if he has bought the jj-th hero, the jj-th character of S[i]S[i] is ‘11’, or ‘00’ if not. The total number of heroes is exactly 100100 .
Output
For each test case , print the answer mod 10000000071000000007 in a single line .
样例输入
0110011100011001001100011110001110001110001010010111111110101010010011010000110100011001001111101011
1000111101111110110100001101001101010001111001001011110001111110101000011101000001011100001001011010
0100101100011110011100110110011100111100010010011001111110101111111000000110001110000110001100001110
1110010101010001000110100011101010001010000110001111111110101010000000001111001110110101110000010011
1000010011111110001101100000101001110100011000111010011111110110111010011111010110101111011111011011
样例输出
515649254
题目来源
题意:有两队打lol,每队可以ban(禁用)5个人物,一共有100个人物,现给出我方拥有人物的情况,给出一个5*100的矩阵,s[i][j]表示第i个人是否有第j个人物,1表示有,0没有(没有的人物肯定是不能选的),问一共有多少种对局情况(敌方假定所有人物都有)
分析:对局情况一共由四种因素构成:
1.我方选择的人物
2.敌方选的的人物
3.我方ban的人物
4.敌方ban的人物
那么ans=我方选择人物的方案数敌方选择人物的方案数我方ban人物的方案数*敌方ban人物的方案数
我方选择人物的方案数可以dp获得,待会再讨论
此时还剩95个人物,敌方要选5个 A(95,5)
我方ban5个人物 C(90,5)
敌方ban5个人物C(85,5)
这里为什么要最后算ban的方案,因为最早算ban的方案在后面我们无法知道到底ban的是哪几个,也就导致了无法dp获取我方选择人物的方案数,于是可以倒着想,先选完人物再ban
num=A(95,5)*C(90,5)*C(85,5)%mod=531192758
接下来需要dp求得我方选择人物的所有方案数
dp[i][j]表示前i个人选1~j里面的人物共有多少种方案数
可得状态转移方程
s[i][j]==0时 dp[i][j]=dp[i][j-1] 第j个人物没有,直接等于选1~j-1个人物时的方案数
s[i][j]==1时 dp[i][j]=dp[i][j-1]+dp[i-1][j-1] 不选第j个人物dp[i][j-1],选第j个人物,那么前面的(1i-1)个人可以在(1j-1)里面随便选,即dp[i-1][j-1]
对这5个人求一下全排列,每个排列进行一次上面的dp(因为每个排列都是一种状态)
将全排列的所有dp[n][m]加起来,再乘上上面的num即为答案
代码:
#include
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
const int mod=1e9+7;
typedef long long ll;
char s[6][105];
ll dp[6][105];
int a[6];
int main()
{
ll num=531192758;
while(~scanf("%s",s[1]+1))
{
ll ans=0;
a[1]=1;
for(int i=2; i<=5; i++)
{
a[i]=i;
scanf("%s",s[i]+1);
}
do
{
mem(dp,0);
for(int i=1; i<=100; i++)
{
dp[1][i]=dp[1][i-1];
if(s[a[1]][i]=='1')
dp[1][i]++;
}
for(int i=2; i<=5; i++)
{
for(int j=1; j<=100; j++)
{
dp[i][j]=dp[i][j-1];
if(s[a[i]][j]=='1')
dp[i][j]=(dp[i][j]+dp[i-1][j-1])%mod;
}
}
ans=(ans+dp[5][100])%mod;
}
while(next_permutation(a+1,a+1+5));
cout<