T - 地狱之门 (URAL - 1036 )

You are given a number 1 ≤ N ≤ 50. Every ticket has its 2 N-digit number. We call a ticket lucky, if the sum of its first N digits is equal to the sum of its last Ndigits. You are also given the sum of ALL digits in the number. Your task is to count an amount of lucky numbers, having the specified sum of ALL digits.

Input

Two space-separated numbers: N and S. Here S is the sum of all digits. Assume that 0 ≤ S ≤ 1000.

Output

The amount of lucky tickets.

Example

inputoutput
2 2
4

Notes

The tickets are 0101, 0110, 1001, 1010 in the example above

// ural 1036. Lucky Tickets
// wa wa ac 0.203s
#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

#define FOR(i,a,b) for(i = (a); i < (b); ++i)
#define FORE(i,a,b) for(i = (a); i <= (b); ++i)
#define FORDE(i,a,b) for(i = (a); i >= (b); --i)

int n, s, ts;
short dp[60][1010][1010];
short endd[1010];

void add(int x, int y, int z)
{
    int s = 0, c = 0, i;

    FOR(i, 0, 150)
    {
        s = c + dp[x][y][i] + dp[x - 1][y - z][i];
        dp[x][y][i] = s % 10;
        c = s / 10;
    }
}

void multi(int t, int j)
{
    int i, s = 0, c = 0;

    FOR(i, 0, 300)
    {
        if(i + j >= 300)
        {
            break;
        }
        s = endd[i + j] + dp[n][ts][i] * t + c;
        endd[i + j] = s % 10;
        c = s / 10;
    }
}

void solve()
{
    int i, j, k;

    cin>>n>>s;
    if(s & 1)
    {
        cout<<"0\n";
        return ;
    }
    ts = s / 2;
    dp[0][0][0] = 1;
    FORE(i, 1, n)
    FORE(k, 0, ts)
    FORE(j, 0, min(k, 9))
    add(i, k, j);
    FOR(i, 0, 150)
    multi(dp[n][ts][i], i);
    FORDE(i, 299, 0)
    if(endd[i] != 0)
    {
        break;
    }
    if(i == -1)
    {
        cout<<"0\n";
    }
    else
    {
        FORDE(j, i, 0)
        cout<<endd[j];
        cout<<endl;
    }
}

int main()
{
    solve();
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ZZ --瑞 hopeACMer

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值