# bzoj2729-[HNOI2012]排队

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

#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
using namespace std;
#define rep(i,l,r) for(register int i=(l);i<=(r);++i)
#define repdo(i,l,r) for(register int i=(l);i>=(r);--i)
#define il inline
typedef double db;
typedef long long ll;

//---------------------------------------
const int bsz=20050,blk=10000;
struct tbig{
int val[bsz];
tbig(){cl();}
tbig(int v){set(v);}
void cl(){memset(val,0,sizeof(val));}
void set(int v){
cl();
while(v){val[++val[0]]=v%blk;v/=blk;}
}
int& operator[](int p){return val[p];}
const int& operator[](int p)const{return val[p];}
void pr(){
printf("%d",val[val[0]]);
repdo(i,val[0]-1,1){
printf("%04d",val[i]);
}
}
};
typedef const tbig& ftbig;
tbig operator+(ftbig l,ftbig r){
tbig res;
res[0]=max(l[0],r[0]);
rep(i,1,res[0]){
res[i]+=l[i]+r[i];
if(res[i]>blk)res[i]-=blk,res[i+1]++;
}
while(res[res[0]+1])++res[0];
return res;
}
tbig operator*(ftbig l,ftbig r){//no fft,no bugs
tbig res;
rep(i,1,l[0]){
rep(j,1,r[0]){
res[i+j-1]+=l[i]*r[j];
if(res[i+j-1]>blk)res[i+j]+=res[i+j-1]/blk,res[i+j-1]%=blk;
}
}
res[0]=l[0]+r[0]+1;
while(res[res[0]]==0&&res[0])--res[0];
return res;
}
tbig a(int a,int b){
if(b>a)return 0;
tbig res(1);
rep(i,1,b)res=res*(a-i+1);
return res;
}
int n,m;
tbig res;
int main(){
ios::sync_with_stdio(0),cin.tie(0);
cin>>n>>m;
res=a(n,n)*(a(n+1,2)*a(n+3,m)+a(m,1)*a(2,2)*a(n+1,1)*a(n+2,m-1));
res.pr();
return 0;
}

posted @ 2018-10-23 19:55  Ubospica  阅读(86)  评论(0编辑  收藏  举报