Lucky Tickets (counting the number of lucky numbers having the indicated sum of ALL digits)

Here is the problem

You are assigned the number 1 ≤ N ≤ 50. Each ticket has a 2-digit number. We call a ticket lucky if the sum of its first N digits is equal to the sum of its last N digits. You also get the sum of ALL digits in the number. Your task is to calculate the number of successful numbers that have the indicated sum of ALL digits.

For input 2 2 output 4 (0101, 0110, 1001, 1010)

Can you help me solve this problem? What is the minimum difficulty?

+3
source share
1 answer

s, s/2. f(n, s/2): n- s/2. f(n, s/2), ( ).

f(n, m): DP. , f(n, m) = f(n-1, m) + f(n-1, m-1) + f(n-1, m-2) + ... + f(n-1, m-9). 0, 1, 2, .. 9 - . k, (n-1) - m - k.

, .

PS - , .

+4

Source: https://habr.com/ru/post/1783664/


All Articles