URAL 1044 Lucky Tickets. Easy!

        和URAL_1036是基本是一样的,具体的思路可以参考我的URAL_1036的解题报告:http://www.cnblogs.com/staginner/archive/2012/05/03/2481332.html

#include<stdio.h>

#include<string.h>

#define MAXD 10

#define MAXS 50

const int N = 4, S = 40;

int f[MAXD][MAXS], ans[MAXD];

void prepare()

{

    int i, j, k, sum;

    memset(f, 0, sizeof(f));

    f[0][0] = 1;

    for(i = 1; i <= N; i ++)

    {

        sum = k = ans[i] = 0;

        for(j = 0; j <= S; j ++)

        {

            if(j - k > 9)

                sum -= f[i - 1][k ++];

            sum += f[i - 1][j];    

            f[i][j] = sum;

            ans[i] += f[i][j] * f[i][j];

        }

    }

}

int main()

{

    int n;

    prepare();

    while(scanf("%d", &n) == 1)

    {

        if(n & 1)

            printf("0\n");

        else

            printf("%d\n", ans[n / 2]);    

    }

    return 0;    

}

 

你可能感兴趣的:(AS)