hdu1261

题意:一个A和两个B一共可以组成三种字符串:"ABB","BAB","BBA".
给定若干字母和它们相应的个数,计算一共可以组成多少个不同的字符串.
 
思路:
(a1+a2+ ... +an)! / a1! / a2! / ... / an!                  大数

 

 

#include 
#include 
const int MAX =505;
struct BigNum
{
    int num[MAX];
    int len;
} a[51][51];

BigNum Div(BigNum &a, int &b)
{
    BigNum c;
    int f;
    int  i, len = a.len;
    memset(c.num, 0, sizeof(c.num));
    f = 0;
    for(i = a.len-1; i >= 0; i--)
    {
        f = f*10+a.num[i];
        c.num[i] = f/b;
        f %= b;
    }
    while(len > 1 && c.num[len-1] == 0) len--;
    c.len = len;
    return c;
}

BigNum Mul1(BigNum &a, int  &b)
{
    BigNum c;
    int  i, len;
    len = a.len;
    memset(c.num, 0, sizeof(c.num));
    //乘以0,直接返回0
    if(b == 0)
    {
        c.len = 1;
        return  c;
    }
    for(i = 0; i < len; i++)
    {
        c.num[i] += (a.num[i]*b);
        if(c.num[i] >= 10)
        {
            c.num[i+1] = c.num[i]/10;
            c.num[i] %= 10;
        }
    }
    while(c.num[len] > 0)
    {
        c.num[len+1] = c.num[len]/10;
        c.num[len++] %= 10;
    }
    c.len = len;
    return  c;
}

int main()
{
    BigNum sum;
    int i,j,m,p[26],s;
    while(scanf("%d",&m),m)
    {
        s=0;
        memset(p,0,sizeof(p));
        for(i=0; i=0; i--)
            printf("%d",sum.num[i]);
        printf("\n");
    }
    return 0;
}


你可能感兴趣的:(ACM,数学题)