# [bzoj2729][HNOI2012]排队 题解 (排列组合 高精)

1 1

## Sample Output

12

$ANS=A_n^n*A_{n+1}^2*A_{n+3}^m+(n+1)*2*A_n^n*m*A_{n+2}^{m-1}$

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=100005;
int n,m,num1[N],num2[N],tot[N];
/*int intlen(int x)
{
return (int)log10(x)+1;
}
void turn(int x,int num[])
{
int l=0;
while(x)
{
int now=x%10;
num[++l]=now;
x/=10;
}
num[0]=l;
//reverse(num+1,num+l+1);
}*/
void mult(int x,int num[])
{
int k=0;
for(int i=1;i<=num[0];i++)
{
int tmp=num[i]*x+k;
num[i]=tmp%10;
k=tmp/10;
}
while(k)num[++num[0]]=k%10,k/=10;
}
void sum(int a1[],int a2[],int res[])
{
int j=1,x=0;
while(j<=a1[0]||j<=a2[0])
{
res[j]=a1[j]+a2[j]+x;
x=res[j]/10;
res[j]%=10;
j++;
}
res[j]=x;
if(!res[j])j--;
res[0]=j;
}
void print(int a[])
{
for(int i=a[0];i;i--)printf("%d",a[i]);
puts(" ");
}
int main()
{
scanf("%d%d",&n,&m);
//turn(n,num1);turn(m,num2);
num1[0]=num1[1]=1;
for(int i=1;i<=n;i++)mult(i,num1);
for(int i=n+1;i>=n;i--)mult(i,num1);
for(int i=n+3;i>=n-m+4;i--)mult(i,num1);
num2[0]=num2[1]=1;
mult(n+1,num2);
mult(m,num2);
mult(2,num2);
for(int i=n+2;i>=n+2-(m-1)+1;i--)mult(i,num2);
for(int i=1;i<=n;i++)mult(i,num2);
//print(num1);print(num2);
sum(num1,num2,tot);
print(tot);
return 0;
}
View Code

posted @ 2019-06-28 12:06  Rorschach_XR  阅读(197)  评论(0编辑  收藏  举报