, C/C++ Programming

Assignment Help:
Question 1 / 1
You have an N x N chessboard and you wish to place N kings on it. Each row and column should contain exactly one king, and no two kings should attack each other (two kings attack each other if they are present in squares which share a corner).

The kings in the first K rows of the board have already been placed. You are given the positions of these kings as an array pos[ ]. pos[i] is the column in which the king in the ith row has already been placed. All indices are 0-indexed. In how many ways can the remaining kings be placed?

Input:
The first line contains the number of test cases T. T test cases follow. Each test case contains N and K on the first line, followed by a line having K integers, denoting the array pos[ ] as described above.

Output:
Output the number of ways to place kings in the remaining rows satisfying the above conditions. Output all numbers modulo 1000000007.

Constraints:
1 <= T <= 20
1 <= N <= 16
0 <= K <= N
0 <= pos_i < N
The kings specified in the input will be in different columns and not attack each other.

Sample Input:
5
4 1
2
3 0

5 2
1 3
4 4
1 3 0 2
6 1
2

Sample Output:
1
0
2
1
18

Explanation:
For the first example, there is a king already placed at row 0 and column 2. The king in the second row must belong to column 0. The king in the third row must belong to column 3, and the last king must beong to column 1. Thus there is only 1 valid placement.

For the second example, there is no valid placement.

Related Discussions:-

Area , Write a program to find the area under the curve y = f(x) between x ...

Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b.

Virtual ATM, #questio A charitable organization wants to design a special A...

#questio A charitable organization wants to design a special ATM machine to be used by needy people. The association supplies the needy person with a pin number to be able to use

Palindrome, Problem : Change to palindrome A palindrome is a string that r...

Problem : Change to palindrome A palindrome is a string that reads the same from both the ends. Given a string S convert it to a palindrome by doing character replacement. Your ta

Compute the canny edges, If we take the input image and smooth it with a Ga...

If we take the input image and smooth it with a Gaussian of a significant size before computing the Canny edges does the number of edges change, and do the locations of these edges

Explain the continue statement, The continue statement The continue sta...

The continue statement The continue statement causes the next iteration of the enclosing loop to start. When this is encountered in the loop , the rest of the statements in the

Write a haskell program, Write a Haskell program that calculates a balanced...

Write a Haskell program that calculates a balanced partition of N items where each item has a value between 0 and K such that the difference between the sum of the values of first

Answer, what is spanning tree? explain prims algorithm spanning tree?

what is spanning tree? explain prims algorithm spanning tree?

STM32F103RET6, traffic light t junction I have 21 LEDs will 6 in each side...

traffic light t junction I have 21 LEDs will 6 in each side 3 for the cars the other 3 will be for the people across the street this will be for each side and the last 3 for show

.., write a c++ code to implement use of a constructor

write a c++ code to implement use of a constructor

How does c++ help with the tradeoff of security vs.usability, A: In C, enca...

A: In C, encapsulation was completed by making things static in a compilation unit or module. It prevented another module from accessing the static stuff. (Incidentally, now static

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd