Placing Cards
InterviewTime limit1sMemory limit256 MB
Given up to 10 cards with 1 or 2 digit numbers, count the distinct integers formed by ordering exactly k chosen cards.
- Level
Easy3 of 10
- Topics
- Brute force, Backtracking, Hash map, Implementation
- Solved
- No attempts yet
Problem
Sanggeun lays cards () side by side on the floor. Each card has a single integer from to written on it. He wants to choose () of the cards and line them up from left to right in the chosen order to form a single integer. How many different integers can he make?
For example, suppose there are 5 cards showing 1, 2, 3, 13, 21. If he picks 3 of them, then laying out 2, 1, 13 in that order gives 2113, and laying out 21, 1, 3 in that order also gives 2113. Because different choices can produce the same integer, you must count only the distinct integers.
Given the numbers written on the cards, write a program that finds how many different integers can be formed by choosing of them.
Input
The first line contains the number of cards , and the second line contains the number of cards to choose . Each of the next lines contains the number written on one card.
Output
Print the number of different integers Sanggeun can make on the first line.
Hint
When the four cards are and , Sanggeun can make the 7 integers .