Problem Statement Print all integer sequences of length N N that satisfy the following…
- User
Problem Statement Print all integer sequences of length N N that satisfy the following conditions, in ascending lexicographical order.
The i i-th element is between 1 1 and R i R i , inclusive. The sum of all elements is a multiple of K K. What is lexicographical order for sequences? Constraints All input values are integers. 1 ≤ N ≤ 8 1≤N≤8 2 ≤ K ≤ 10 2≤K≤10 1 ≤ R i ≤ 5 1≤R i ≤5 Input The input is given from Standard Input in the following format:
N N K K R 1 R 1
R 2 R 2
… … R N R N
Output Print the answer in the following format, where X X is the number of sequences to print, the i i-th of which is A i
( A i , 1 , A i , 2 , … , A i , N ) A i =(A i,1 ,A i,2 ,…,A i,N ):
A 1 , 1 A 1,1
A 1 , 2 A 1,2
… … A 1 , N A 1,N
A 2 , 1 A 2,1
A 2 , 2 A 2,2
… … A 2 , N A 2,N
⋮ ⋮ A X , 1 A X,1
A X , 2 A X,2
… … A X , N A X,N
Sample 1 Inputcopy Outputcopy 3 2 2 1 3 1 1 2 2 1 1 2 1 3 There are three sequences to be printed, which are ( 1 , 1 , 2 ) , ( 2 , 1 , 1 ) , ( 2 , 1 , 3 ) (1,1,2),(2,1,1),(2,1,3) in lexicographical order.
Sample 2 Inputcopy Outputcopy 1 2 1 There may be no sequences to print. In this case, the output can be empty.
Sample 3 Inputcopy Outputcopy 5 5 2 3 2 3 2 1 1 1 1 1 1 2 2 3 2 1 3 1 3 2 1 3 2 2 2 1 3 2 3 1 2 1 2 3 2 2 2 1 3 2 2 2 2 2 2 2 2 2 3 1 2 3 1 2 2 2 3 1 3 1 2 3 2 1 2 2 3 2 2 1 Sualda nə deyilir?Və idea və hint verki necə etmək olar
- Assistant