P5505 [JSOI2011]分特产(容斥多重集组合数)

在这里插入图片描述
思路:不难联想到是组合数学那一类题目偏多,给你m种球,每个有 a i a_i ai个球,要求放入 n n n个盒子里面,求盒子中都有球的方案。
浓浓的组合数学味道,可惜我写的不多,滚去看题解了
考虑一下补集转换,先求允许空集的方案,再减去盒子中包含空盒的方案.
奉上笔记一页,供大家参考思路.
在这里插入图片描述

/*
Stairs upon the temple
I climb and I crawl in
People travel millions of miles just to see it
But they never conquer this way
*/
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1000+5;
const int INF = 1e9+7;
typedef long long ll;
typedef pair<int,int> pii;
#define all(a) (a).begin(), (a).end()
#define pb(a) push_back(a)
vector<int> G[maxn];
ll mod = 1e9+7;
ll pw(ll a,ll b){
	ll ans = 1;a%=mod;
	while(b){
		if(b&1) ans=ans*a%mod;
		b>>=1;a=a*a%mod; 
	}
	return ans%mod;
}
ll inv(ll a){
	return pw(a,mod-2);
}
ll fac[maxn*2];
ll C(ll n,ll m){
	return fac[n]*inv(fac[m])%mod*inv(fac[n-m])%mod;
}
int a[maxn];
int main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	fac[0] =1;
	for(int i=1;i<=2002;i++) fac[i] = fac[i-1]*i%mod;
	int n,m;cin>>n>>m;
	for(int i=1;i<=m;i++) cin>>a[i];
	ll ans = 0;
	for(int i=0;i<n;i++){
		ll res = C(1LL*n,1LL*i);
		for(int j=1;j<=m;j++){
			res = (res * C(1LL*a[j]+n-i-1,1LL*n-i-1))%mod;
		}
		if(i&1) ans = ((ans-res)%mod+mod)%mod;
		else ans = (ans + res)%mod;
	}
	cout<<ans<<"\n"; 
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

minato_yukina

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值