Because it is written does not move, so the chicken dish decadent blog for the future development of the great Austrian letter made little contribution
Title Description
There are a middle school male students n, m female students and two teachers to queue up to attend a medical examination. They lined up in a straight line, and can not be any adjacent two female students, two teachers can not be adjacent, then a total of how many rows of law do? (Note: any two people are different)
Input Format
Only one line is separated by spaces and two non-negative integers n and m, its meaning as described above.
For 30% of the data n≤100, m≤100
to 100% of the data n≤2000, m≤2000
Output Format
Output.txt output file contains only a non-negative integer representing the number of rows of different methods. Note that the answer may be significant.
Sample input
1 1
Sample Output
12
题解:
这是一道组合数学,应该说是非常明显。
首先我们需要一个数奥生思路开始要正确。
我们选择固定男生和老师,然后将女生插空,貌似如果固定女生的式子会非常麻烦。我写到一半果断放弃了
固定男生时是A(n,n);
固定老师时分两种情况:
老师卡在一起,也就是老师一起站在两个男生中间,是A(2,2),这时需要一个女生站在老师中间,总式子变成A(n,n)*(n+1)*A(2,2)*A(n+2,m-1),m-1在上面。
或者老师没有卡在一起,是A(n+1,2),然后女生插空,总式子变成A(n,n)*A(n+1,2)*A(n+3,m).
合并式子,最终是n!*(2*m+n*(n+3))*(n+1)*(n+2)!/(n-m+3)!。
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #define maxn 100010 5 using namespace std; 6 int n,m,a[maxn],b[maxn],c[maxn]; 7 void mult(int a[],int b) 8 { 9 int x=0; 10 for(int i=1;i<=a[0];i++) 11 { 12 int tmp=a[i]*b+x; 13 a[i]=tmp%10; 14 x=tmp/10; 15 } 16 while(x) 17 { 18 a[++a[0]]=x%10; 19 x/=10; 20 } 21 } 22 23 int main() 24 { 25 scanf("%d%d",&n,&m);a[0]=a[1]=1; 26 for(int i=1;i<=n;i++) mult(a,i); 27 mult(a,(2*m+n*(n+3))); 28 mult(a,n+1); 29 for(int i=n-m+4;i<=n+2;i++) mult(a,i); 30 for(int i=a[0];i>0;i--) printf("%d",a[i]); 31 return 0; 32 }
大概就是这样。