34. Little Bishops

A bishop is a piece used in the game of chess which is played on a board of square grids. A bishop can only move diagonally from its current position and two bishops attack each other if one is on the path of the other. In the following figure, the dark squares represent the reachable locations for bishop B1 form its current position.  The figure also shows that the bishops B1 and B2 are in attacking positions whereas B1 and B3 are not. B2 and B3 are also in non-attacking positions.

Now, given two numbers n and k, your job is to determine the number of ways one can put k bishops on an n × n chessboard so that no two of them are in attacking positions.

Input

The input file may contain multiple test cases. Each test case occupies a single line in the input file and contains two integers n (1 ≤ n ≤ 8) and k (0 ≤ k ≤ n2).

A test case containing two zeros for n and k terminates the input and you won't need to process this particular input.

Output

For each test case in the input print a line containing the total number of ways one can put the given number of bishops on a chessboard of the given size so that no two of them are in attacking positions. You may safely assume that this number will be less than 1015.


测试输入关于“测试输入”的帮助期待的输出关于“期待的输出”的帮助时间限制关于“时间限制”的帮助内存限制关于“内存限制”的帮助额外进程关于“{$a} 个额外进程”的帮助
测试用例 1以文本方式显示
  1. 8 6↵
  2. 4 4↵
  3. 0 0↵
以文本方式显示
  1. 5599888↵
  2. 260↵
1秒64M0


//看了讨论区里大佬给的打表的思路很6
#include<stdio.h>

int main()
{
	int n, k;
	int Map[9][16] =
	{
		{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
		{ 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
		{ 1, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
		{ 1, 9, 26, 26, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
		{ 1, 16, 92, 232, 260, 112, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
		{ 1, 25, 240, 1124, 2728, 3368, 1960, 440, 32, 0, 0, 0, 0, 0, 0, 0 },
		{ 1, 36, 520, 3896, 16428, 39680, 53744, 38368, 12944, 1600, 64, 0, 0, 0, 0, 0 },
		{ 1, 49, 994, 10894, 70792, 282248, 692320, 1022320, 867328, 389312, 81184, 5792, 128, 0, 0, 0 },
		{ 1, 64, 1736, 26192, 242856, 1444928, 5599888, 14082528, 22522960, 22057472, 12448832, 3672448, 489536, 20224, 256, 0 }
	};
	while (scanf("%d %d",&n,&k) && (n+k))
		printf("%d\n", Map[n][k]);
	return 0;
}





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值