{"problem":{"name":"G. Count Permutations","description":{"content":"Given N and K, count number of permutations of [1, 2, 3...N] in which no two adjacent elements differ by more than K. For example, permutation [4, 1, 2, 3] cannot be counted for . First line contains","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":1000,"memory_limit":524288},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF10058G"},"statements":[{"statement_type":"Markdown","content":"Given N and K, count number of permutations of [1, 2, 3...N] in which no two adjacent elements differ by more than K. For example, permutation [4, 1, 2, 3] cannot be counted for .\n\nFirst line contains T(1 ≤ T ≤ 10), the number of test cases. Each test case consists of N(1 ≤ N ≤ 15) and K(0 ≤ N) in single line.\n\nFor each test case print the required answer in one line.\n\nExample case 1. All permutations are valid.\n\nExample case 2. Permutations [1, 2, 3, [3, 2, 1]] are counted.\n\n## Input\n\nFirst line contains T(1 ≤ T ≤ 10), the number of test cases. Each test case consists of N(1 ≤ N ≤ 15) and K(0 ≤ N) in single line.\n\n## Output\n\nFor each test case print the required answer in one line.\n\n[samples]\n\n## Note\n\nExample case 1. All permutations are valid.Example case 2. Permutations [1, 2, 3, [3, 2, 1]] are counted.","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"**Definitions**  \nLet $ T \\in \\mathbb{Z} $ be the number of test cases.  \nFor each test case $ i \\in \\{1, \\dots, T\\} $:  \n- $ N_i \\in \\mathbb{Z} $ denotes the size of the set $ \\{1, 2, \\dots, N_i\\} $.  \n- $ K_i \\in \\mathbb{Z} $ denotes the maximum allowed absolute difference between adjacent elements.  \n\nLet $ \\mathcal{P}_{N_i} $ be the set of all permutations of $ \\{1, 2, \\dots, N_i\\} $.  \n\n**Constraints**  \n1. $ 1 \\leq T \\leq 10 $  \n2. For each test case $ i $:  \n   - $ 1 \\leq N_i \\leq 15 $  \n   - $ 0 \\leq K_i \\leq N_i - 1 $  \n\n**Objective**  \nFor each test case $ i $, compute the number of permutations $ \\pi \\in \\mathcal{P}_{N_i} $ such that for all $ j \\in \\{1, 2, \\dots, N_i - 1\\} $:  \n$$\n|\\pi(j+1) - \\pi(j)| \\leq K_i\n$$","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF10058G","tags":[],"sample_group":[],"created_at":"2026-03-03 11:00:39"}}