#532 Placing Bishops on a Chessboard
For New Year, a girl named Anya wished for a chessboard of size n × n.
Thanks to a New Year miracle, her wish came true, and she also received k chess bishops.
Anya has studied mathematics for several years, so she became interested in the following question:
in how many ways can exactly k bishops be placed on this board so that no two bishops attack each other according to chess rules?
She is not good at programming, so she asks you to calculate this value.
Because the answer may be very large, print it modulo 10⁹ + 7.
Input
The only line contains two numbers n and k:
1 ≤ n ≤ 500
1 ≤ k ≤ n²
where n is the board size and k is the number of bishops.
Output
Print exactly one number — the number of ways to place k bishops on the board so that no two bishops attack each other.
Print the answer modulo 10⁹ + 7.
Example 1
Input:
5 3
Output:
1124
Example 2
Input:
2 2
Output:
4
Example 3
Input:
4 3
Output:
232
Question review
This is just one of the solutions available with Premium. And more:
- 250+ advanced lectures
- 1300+ practice exercises
- 500+ solutions to problems from real interviews
- Personalized Java Hub certificates
- Expanded access to the AI mentor