PIN Code Possibilities
InterviewTime limit3sMemory limit256 MB
Count n-digit codes with leading zeros allowed whose digits add up to s for each test case.
- Level
Easy3 of 10
- Topics
- Dynamic programming, Combinatorics
- Solved
- No attempts yet
Problem
A PIN (Personal Identification Number) is a secret code that only its owner knows. PINs are used for authentication in many places, such as ATMs and telephone call centers. A PIN usually has four digits or more, and the number of digits depends on the required level of security. The more digits a PIN has, the harder it is to guess.
The total number of PINs is easy to count. Each position holds one of the ten digits 0 to 9, so a PIN with digits has possibilities. If you know something about the PIN, for example the sum of all of its digits, the number of candidates drops.
For a 3-digit PIN whose digits sum to 1, only three codes work: 001, 010 and 100. If the sum is 2, there are six: 011, 101, 110, 002, 020 and 200.
Given the number of digits and the sum of all digits , write a program that counts the possible PINs. A leading zero is allowed.
Input
The input consists of several test cases. Each line contains the number of digits and the sum of all digits , separated by a space. (, )
There are at most 1000 test cases. Process the input until it ends.
Output
For each test case, print the number of PINs that satisfy the condition, one per line. If no PIN satisfies the condition, print 0.