Description
There are \ (n \) classmates and \ (m \) specialty products.
Find the number of solutions
\(n,m\le10^3\)
Solution
Let's get started
Suppose we don't need to consider the situation without special products, directly upload the statistical method of the board method
Then we consider this to subtract the situation where someone has no specialty
First, there is a man without deleting specialty situations, is given to \ (n-1 \) personal chant
Here we found that if directly \ (f_n-f_ {n-1} \) is obviously a fake approach
Because by definition, this \ (f_ {n-1} \) is likely to be assigned by \ (n-2 \) individuals, but not by \ (1 \) individuals
So we have to continue to rebuke
Another: Since we do n’t know which \ (i \) individual was not assigned, we still have to multiply it by one \ (\ binom {n} {ni} \)
Code
#include<bits/stdc++.h>
using namespace std;
#define int long long
namespace yspm{
inline int read()
{
int res=0,f=1; char k;
while(!isdigit(k=getchar())) if(k=='-') f=-1;
while(isdigit(k)) res=res*10+k-'0',k=getchar();
return res*f;
}
const int N=3e3+10,mod=1e9+7;
int inv[N],fac[N];
inline void prework()
{
fac[0]=1; inv[0]=1; inv[1]=1;
for(int i=1;i<N;++i) fac[i]=fac[i-1]*i%mod;
for(int i=2;i<N;++i) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
for(int i=1;i<N;++i) inv[i]*=inv[i-1],inv[i]%=mod;
return ;
}
inline int C(int n,int m)
{
if(n<0||m<0||n<m) return 0;
return inv[n-m]*inv[m]%mod*fac[n]%mod;
}
int a[N],n,m,ans,f[N];
signed main()
{
prework();
n=read(); m=read();
for(int i=1;i<=m;++i) a[i]=read();
for(int i=1;i<=n;++i)
{
f[i]=1;
for(int j=1;j<=m;++j) f[i]*=C(a[j]+i-1,i-1),f[i]%=mod;
}
for(int i=0;i<=n;++i)
{
if(i&1)
{
ans-=C(n,i)*f[n-i];
ans+=mod; ans%=mod;
}
else
{
ans+=C(n,i)*f[n-i]%mod;
ans%=mod;
}
}cout<<ans<<endl;
return 0;
}
}
signed main(){return yspm::main();}
Review
When we solve the problem of tolerance, we need to use a variety of combinations
At the same time, accurately find duplicate information and then enumerate and repel