# [BZOJ 2729][HNOI2012]排队（组合数学+高精）

Description

Solution

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
typedef long long LL;
using namespace std;
struct Bign
{
static const int base=100000;
static const int width=5;
LL len,s[10010];
Bign()
{memset(s,0,sizeof(s));len=1;}
Bign(int num){*this=num;}
void clear(){while(len>1&&!s[len-1])len--;}
Bign operator = (int num)
{
len=0;
while(num)
{
s[len++]=num%base;
num/=base;
}
return *this;
}
Bign operator + (const Bign& b)
{
Bign c;c.len=0;
for(int i=0,g=0;g||i<max(len,b.len);i++)
{
int x=g;
if(i<b.len)x+=b.s[i];
if(i<len)x+=s[i];
c.s[c.len++]=x%base;
g=x/base;
}
return c;
}
Bign operator * (const Bign& b)
{
Bign c;c.len=len+b.len;
for(int i=0;i<len;i++)
{
for(int j=0;j<b.len;j++)
{
c.s[i+j]+=s[i]*b.s[j];
}
}
for(int i=0;i<c.len;i++)
{
c.s[i+1]+=c.s[i]/base;
c.s[i]%=base;
}
c.clear();
return c;
}
Bign operator * (const int& b)
{
Bign c;
c.len=0;
for(int i=0,g=0;g||i<len;i++)
{
int x;
if(i<len)x=s[i]*b+g;
else x=g;
c.s[c.len++]=x%base;
g=x/base;
}
return c;
}
void print()
{
string res;
printf("%d",s[len-1]);
for(int i=len-2;i>=0;i--)
printf("%05d",s[i]);
}
};
Bign A(int x,int y)
{
if(x>y)return Bign();
Bign c=1;
for(int i=y-x+1;i<=y;i++)
c=c*i;
return c;
}
int n,m;
int main()
{
scanf("%d%d",&n,&m);
Bign ans;
ans=A(n,n)*(A(2,n+1)*A(m,n+3)+A(1,n+1)*A(2,2)*A(1,m)*A(m-1,n+2));
ans.print();
return 0;
} 

posted @ 2017-04-20 21:45  Zars19  阅读(192)  评论(0编辑  收藏  举报