UVALive - 8521-LOL - ( 排列组合 )

该博客讨论了一种计算5人团队在拥有100个英雄的情况下,对阵另一5人团队的出战和禁用英雄的方案数量的方法。通过四个嵌套循环确定己方队伍的出战英雄,然后计算剩余英雄的选择可能性,最后乘以组合数得出总方案数。代码实现了这一逻辑并给出了结果。
题目链接:点击进入
题目

在这里插入图片描述

题意

5 个人,100 个英雄,给你 5 个人关于 100 英雄的拥有情况( 0 - 没有,1 - 有 ),每个人用一个,办一个,除去自己队伍的五个人,对面队伍的五个人也是用 5 个办 5 个,求双方对战方案数。

思路

四个 5
自己队伍 5 个出战( 必须是自己有的才可以出战 )
自己队伍 5 个禁用( 当出战确定,禁用的就是,剩下的 95 个 中选 5 个,有序 )
对面队伍 5 个出战( 剩下的 90个 中选 5 个,无序 )
对面队伍 5 个禁用( 剩下的 85个 中选 5 个,无序 )
现在主要问题变为了确定自己队伍出战的方案数。
因为英雄只有 100 个,四个 for 循环暴力确定自己队伍前四名成员所选用英雄,对于最后一人,根据前四名成员所选英雄确定剩余可选方案,将其计入答案 ans 。
最终答案 = ans * A ( 95 , 5 ) * C ( 90 , 5 ) * C ( 85 , 5 ) 。

代码
#include<iostream>
#include<string>
#include<map>
#include<set>
//#include<unordered_map>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<fstream>
#define X first
#define Y second
#define best 131 
#define INF 0x3f3f3f3f3f3f3f3f
#define pii pair<int,int>
#define lowbit(x) x & -x
#define inf 0x3f3f3f3f
//#define int long long
//#define double long double
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double pai=acos(-1.0);
const int maxn=1e6+10;
const int mod=1e9+7;
const double eps=1e-9;
int t,a[maxn],k;
string s[10];
int A(int n,int m)
{
	int res=1;
	for(int i=m+1;i<=n;i++)
		res=res*i;
	return res;
} 
int C(int n,int m)
{
	int res=1;
	for(int i=m+1;i<=n;i++)
		res=res*i/(i-m);
	return res;
}
int main()
{	
//	ios::sync_with_stdio(false);
//	cin.tie(0);cout.tie(0);
	while(cin>>s[1]>>s[2]>>s[3]>>s[4]>>s[5])
	{
		int sum=0,ans=0;
		for(int i=0;i<100;i++)
			if(s[5][i]=='1') 
				sum++;
		for(int i=0;i<100;i++)
		{
			if(s[1][i]=='0') continue;
			for(int j=0;j<100;j++)
			{
				if(s[2][j]=='0'||i==j) continue;
				for(int z=0;z<100;z++)
				{
					if(s[3][z]=='0'||z==i||z==j) continue;
					for(int k=0;k<100;k++)
					{
						if(s[4][k]=='0'||k==i||k==j||k==z) continue;
						int tmp=sum;
						if(s[5][i]=='1') tmp--;
						if(s[5][j]=='1') tmp--;
						if(s[5][z]=='1') tmp--;
						if(s[5][k]=='1') tmp--;
						ans=ans+tmp;
					}
				}
			}
		}
		int res=ans*A(95,5)%mod*C(90,5)%mod*C(85,5)%mod;
		cout<<res<<endl;
	}
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值