NOVICE43 - Problem 3

When I first learned backtracking I made a program to find all the permutations of the English alphabets in lexicographically increasing. Filled with elation I showed the program to Rohil. Rohil being someone who likes to do stuff off the league was not impressed and gave me the following variation of the problem help me to solve the problem: 

You have to find the number of permutations of length N (1<=N<=11) such that at whenever an alphabet (say 'c' ) appears in the permutation all the alphabets smaller than 'c' should have appeared before it at least once. An alphabet is smaller than another if it appears before the other in the English alphabet. ‘a’ being the smallest and ‘z’ being the largest. For example when N=2 then aa, ab are the only valid permutations and ba, bb is invalid since in ba all the alphabets smaller than b have not appeared at least once before it. See example for further clarification.

Input

Line 1: T (number of test cases)

Line 2: n1

Line 3: n2

Output

Line 1: number of such permutations of length n1

...

Example

Input:
2
2
3

Output:
2
5

Explanation for N=3, the possible permutations are: abc, aba, abb, aab, aaa


Added by:Mahesh Chandra Sharma
Date:2011-03-01
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:NSIT Noivce contest #4

hide comments
2013-06-22 03:25:59 technophyle
The answer for N=11 is 6785**
2013-05-22 05:23:50 Rishikesh Jha
why is this problem in classical ?
Shift to tutorial.
2012-12-15 11:43:54 Shubham Somani
If u cant do the math, then do the recursion :D
2012-07-09 14:14:47 Romal Thoppilan
Then whats the answer for n=11 , even i,m getting 182905 ... ?
2012-01-10 11:25:20 saket diwakar
@Aseem
no
2011-06-09 19:21:06 Aseem Kumar
isn't the answer for N=11 1829** ?
2011-04-23 19:18:02 :D
yes
2011-04-23 16:08:35 Ikhaduri
will the answer fit into a 64 bit integer?


Last edit: 2011-11-21 14:40:40
2011-03-04 11:51:12 Mahesh Chandra Sharma
NOVICE43 specify that it is the 3rd problem of 4th Novice contest in which problems are always named by their index. And it doesn't look like a creativity contest though :-)
2011-03-02 17:31:03 hendrik
There is already a Problem 3 (NOVICE23).
Cant you be a little bit more creative?
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.