discriptionJyy led participated in a number of ACM/ICPC competitions, brought back a lot of native products, to be divided into the laboratory students. Jyy want to know, how many different ways to divide these specialties into n classmates? Of course, jyy do not want any of the students because they did not get a special product and feel lost, so every classmate must at least a specialty. For example, Jyy brought 2 bags of twist and 1 bags of steamed buns to a and B two students, then a total of 4 different distribution methods: A: Twist, B: Twist, Bun A: Twist, twist, B: Bun A: Steamed buns, B: Twist, twist A: Twist, bun, B: Twist
InputThe first line of input data is the number of students n and the number of specialties M. The second line contains m integers, representing the number of each specialty. N, M not exceeding 1000, the number of each specialty is not more than 1000
OutputThe output line, the total number of different allocation schemes. Since the output can be very large, you only need to output the value of MoD 1,000,000,007 for the final result.
Sample Input54 1 3) 3 5
Sample Output
384835
Hint
A simple combination of mathematics,,, can be a combination of water over 23333.
Set g (i) for the number of programs that have at least I person a specialty, then g (i) = C (n,i) *πc (N-i-1+a[j], a[j]) is the option to consider who has not chosen the chosen candidate.
Set F (i) for a special product with I have no number of programs, you can find that an F (i) will be counted C (I,J) in a G (j), so we construct a tolerance coefficient,
Make for the I that we need, σx[j] * C (I,J) = 1; For the other I, Σx[j] * C (I,J) = 0.
What we need is just f[0], so this coefficient is very good structure, so that all the odd J X is 1, even the number of 1 on the line, just this is also our common coefficient of repulsion, so can not construct also water over the subject 233
#include <bits/stdc++.h> #define LL long longusing namespace std;const int Ha=1000000007;const int maxn=2005;using namespace Std;int c[maxn][maxn];int n,m,a[maxn];int g[maxn];inline int Add (int x,int y) {X+=y;return x>=ha?x-ha:x;} inline void init () {c[0][0]=1;for (int i=1;i<=2000;i++) {c[i][0]=1;for (int j=1;j<=i;j++) C[i][j]=add (C[i-1][j-1] , C[i-1][j]);}} inline void Solve () {for (int i=0,lef;i<=n;i++) {g[i]=c[n][i],lef=n-i-1; for (int j=1;j<=m;j++) g[i]=g[i]* (LL) C[a[j]+lef][a[j]]%ha;} int ans=0;for (int i=0;i<=n;i++) {if (i&1) Ans=add (Ans,ha-g[i]); else Ans=add (Ans,g[i]);} printf ("%d\n", ans);} int main () {init (); scanf ("%d%d", &n,&m), for (int i=1;i<=m;i++) scanf ("%d", a+i), solve (); return 0;}
[JSOI2011] Sub-specialty