跳到正文

题解

题解 P1358 【扑克牌】

weak_ddb约 2 分钟
原文
文章信息与版本

文章信息

发布
2019年8月13日
收录
2025年12月12日
更新
2026年11月17日
篇幅
约 2 分钟
获赞
35
题目
P1358

版本

  1. v1当前

题目链接

很明显,对于喜欢打扑克牌的有数学细胞的人,从NN张牌中取MM张牌,是组合问题(取牌没有顺序),取牌数量为CC mn{m \atop n}

求组合数有两种方法,一是用排列做分数,二是递归,三是递推,也就是杨辉三角

11

11 11

11 22 11

也就是对应

CC 11{1\atop1}

CC 12{1\atop2} CC 22{2\atop2}

CC 13{1\atop3} CC 23{2\atop3} CC 33{3\atop3}

略微排版不整齐,请管理员和读者包容一下。


在C++C++中,我们可以用递推方法

C++
a[0][0]=1;
	for(int i=1;i<=10000;i++)
		for(int j=0;j<=100;j++)
			a[i][j]=(a[i-1][j-1]+a[i-1][j])%10007;//杨辉三角等于左上角的数值+右上角的数值

每个人分别计算一下就好了,记得%1000710007

C++
#include<bits/stdc++.h>
using namespace std;
long long n,m,s=1,t;
long long a[10005][105];
int main()
{
	cin>>n>>m;
	a[0][0]=1;
	for(int i=1;i<=10000;i++)
		for(int j=0;j<=100;j++)
			a[i][j]=(a[i-1][j-1]+a[i-1][j])%10007;
	for(int i=1;i<=m;i++){
		cin>>t;
		s=s*a[n][t]%10007;
		n-=t;//牌已经被抽走了,要减掉
	}
	cout<<s;
	return 0;
}