CWAY - Đếm số đường đi trên đồ thị đầy đủ

Tác giả: hieult

Ngôn ngữ: C++

#include <cstdio>
//#include <conio.h>
#define base 10000

int a[1000];
int scs;

void print()
{
     printf("%d",a[scs]);
     for(int i = scs-1;i>=1;i--) printf("%04d",a[i]);
}

int main()
{
    int n;
    scanf("%d",&n);
    a[1] = 1;scs = 1;
    for(int i = 1;i<=n-2;i++)
    {
        int du = 0,temp;
        temp = a[1];
        a[1] = (temp*i+1)%base;
        du = (temp*i+1)/base;
        for(int j = 2;j<=scs;j++)
        {
            temp = a[j];
            a[j] = (temp*i+du)%base;
            du = (temp*i+du)/base;
        }
        if(du>0) a[++scs] = du;
    } 
    print();
    //getch();           
}

Download