Bzoj4710 [Jsoi2011] sub-specialty

Source: Internet
Author: User

Time Limit:10 Sec Memory limit:128 MB
submit:96 solved:62
[Submit] [Status] [Discuss] Descriptionjyy 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

Input data The first line 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

Output outputs a row with 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 Input5 4
1 3 3 5Sample Output384835HINT Source

Mathematical problem Combination number tolerance

1#include <iostream>2#include <cstdio>3#include <algorithm>4#include <cstring>5 #defineLL Long Long6 using namespacestd;7 Const intmxn= .;8 Const intmod=1e9+7;9 intRead () {Ten     intx=0, f=1;CharCh=GetChar (); One      while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} A      while(ch>='0'&& ch<='9') {x=x*Ten-'0'+ch;ch=GetChar ();} -     returnx*F; - } the LL FAC[MXN],INV[MXN]; - voidinit () { -fac[0]=fac[1]=1; -inv[0]=inv[1]=1; +      for(intI=2; i<mxn;i++){ -fac[i]= (LL) fac[i-1]*i%MoD; +Inv[i]= ((-mod/i) *inv[mod%i]%mod+mod)%MoD; A     } at      for(intI=2; i<mxn;i++) -inv[i]= (LL) inv[i]*inv[i-1]%MoD; -     return; - } -LL Calc (intNintm) { -     if(!m)return 1; in     if(n<m)return 0; -     return(LL) fac[n]*inv[m]%mod*inv[n-m]%MoD; to } + intn,m; - inta[mxn],smm=0; the LL F[MXN]; * intMain () { $     inti,j;Panax Notoginseng init (); -N=read (); m=read (); the      for(i=1; i<=m;i++) +a[i]=read (); A      for(i=1; i<=n;i++){ thef[i]=1; +          for(j=1; j<=m;j++) -F[i]=f[i]*calc (I-1+A[J],A[J])%MoD; $          for(j=1; j<i;j++){ $F[i]= (F[i]-f[j]*calc (i,j)%mod+mod)%MoD; -         } -     } theprintf"%lld\n", F[n]); -     return 0;Wuyi } the 

Bzoj4710 [Jsoi2011] sub-specialty

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.