Permutation

3

8 votes
Introduction to Dynamic Programming-2, Algorithms, Medium, DP, Dynamic Programming
Problem

You are given a number N.
Create a set S containing the digits of the number N.(set has only 1 occurence of each element).Using this set create a number X.
Choose a subsequence of indices from the number N and create a number Y.
You need to tell the number of distinct numbers Y that can be created such that X and Y are permutation of each other.

Note: X and Y may have leading 0's.
Constraints

1T100
1LengthOf|N|100
Each character is digit (i.e '0' to '9'). 

Input Format 

First line contains T (the number of testcases).
Each testcase contains a Number N 

Output Format 
In each line print the number of distinct  possible values of Y.
 

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

For testcase 1, the distinct possible Y's are 01.

For testcase 2, the distinct possible Y's are 01 and 10.

Editor Image

?