BZOJ2729 HNOI2012排队(组合数学+高精度)

  组合入门题。高精度入门题。

#include<iostream> 
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int read()
{
    int x=0,f=1;char c=getchar();
    while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
    while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
    return x*f;
}
#define N 1000010
int n,m,a[N],len;
void update()
{
    for (int j=1;j<=len;j++)
    a[j+1]+=a[j]/10,a[j]%=10;
    while (a[len+1]) len++,a[len+1]+=a[len]/10,a[len]%=10;
}
void mul(int i)
{
    for (int j=1;j<=len;j++)
    a[j]*=i;
    update();
}
int main()
{
    n=read(),m=read();
    if (m==0)
    {
        a[1]=1;len=1;
        for (int i=2;i<=n+1;i++) mul(i);
        mul(n);
    }
    else
    {
        a[1]=2*m+n*(n+3);update();
        for (int i=2;i<=n+1;i++) mul(i);
        for (int i=n+2;i>n+3-m;i--) mul(i);
    }
    while (!a[len]&&len>1) len--;
    for (int i=len;i;i--) printf("%d",a[i]);
    return 0;
}

 

posted @ 2018-09-06 13:03  Gloid  阅读(165)  评论(0编辑  收藏  举报