Medium Divide and Conquer > Dynamic Programming

Shin Chan is no longer a kid now. Rather he has become a very good programmer as well as mathematician. He loves inventing new properties of numbers. He has invented a new special kind of number called K-Perfect number. He calls a positive integer N as K-Perfect if N contains **only** the integers 1 to K in an arbitrary order and each integer from 1 to K appears **exactly once**. It’s very easy to generate K-Perfect number. Shin Chan takes an array and then adds K integers (1 to K) in the array and then shuffles it. After that he takes a blank string and then concatenates the elements of array one after another with the string. The resulting string is a K-Perfect number. Look at the following samples: ![Image about explaining K-Perfect number][1] We do not know what will be the K-Perfect number generated by Shin Chan as it is dependent on the order of shuffling. But it is obvious that for any K, there exists exactly **K!** (factorial of K) K-perfect numbers. Anyways, Shin Chan is tensed because recently Himawari just attacked his laptop and Shin Chan has no idea whether Himawari has messed up with his code of K-Perfect number generator. So to check whether his code is okay, can you help him? Input: ------ Input starts with an integer **T (T ≤ 30)** denoting the number of test cases. Each case gives you an integer **K (1 ≤ K ≤ 18)** and a positive integer **N** in separate lines. The number of digits in **N** does not exceed **50**. Output: ------- For each case, print **“YES”** if the given number is K-Perfect and **“NO”** otherwise without the quotes. Sample Input ------------ 4 4 4132 5 425132 12 112345678910112 12 123456781901112 Sample Output ------------- YES NO YES NO [1]: https://s3-ap-southeast-1.amazonaws.com/devskillimagestorage/questionimages/59cf8e45-26e7-ca7c-9038-08d3d31d8bbc_ceed666a6ce24995b4c70222ab31393f_W634xH108.png

Ariful Hoque Maruf