Weight of Numbers
All submissions for this problem are available.
Let us denote an n digit decimal number by a1a2a3...an with the condition that each ai should be between 0 and 9 inclusive except a1 which should be between 1 and 9 inclusive. The weight of such a number is defined as the sum of absolute difference between adjacent numbers. Precisely the weight can be defined as,
weight = 0 For i = 1 to n-1 weight = weight + ABS(ai+1 - ai)
Here ABS is the absolute value of the argument.
Given n and a weight w, find all the n digit numbers having a weight w. Since the answer could be very large, print the answer modulo 1000007.
The first line contains one integer t, the number of testcases. (1 <= t <= 150)
This will be followed by t lines each consisting of numbers n and w.
- 2 <= n <= 20
- 0 <= w <= 200
For each test case print the answer modulo 1000007 in a separate line.
2 10 0 2 1
|Time Limit:||0.248842 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, COB, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.