Little Bishops uva861
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 andB3 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 i
#include"iostream"
#include"cstring"
#include"algorithm"
using namespace std;
const int N=;
int b[N+],w[N+],rb[N+][],rw[N+][];
void init_chessboard(int n)
{
memset(b,,sizeof(b));
memset(w,,sizeof(w));
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
{
if((i+j)&)
w[(i+j)>>]++;
else
b[(i+j)>>]++;
}
}
void bishops(int n,int k,int c[N+],int R[N+][])
{
for(int i=;i<=n;i++)
R[i][]=;
for(int j=;j<=k;j++)
R[][j]=;
for(int i=;i<=n;i++)
for(int j=;j<=c[i];j++)
R[i][j]=R[i-][j]+R[i-][j-]*(c[i]-j+);
}
int main()
{
int n,k,ans;
while(scanf("%d%d",&n,&k)!=EOF)
{
if(n==&&k==)
break;
init_chessboard(n);
sort(b+,b+n+);
sort(w+,w+n);
bishops(n,k,b,rb);
bishops(n-,k,w,rw);
ans=;
for(int i=;i<=k;i++)
ans+=rb[n][i]*rw[n-][k-i];
printf("%d\n",ans);
}
return ;
}
n 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.
Sample Input
8 6
4 4
0 0
Sample Output
5599888
260
Little Bishops uva861的更多相关文章
- codeforces Gargari and Bishops(很好的暴力)
/* 题意:给你一个n*n的格子,每一个格子都有一个数值!将两只bishops放在某一个格子上, 每一个bishop可以攻击对角线上的格子(主对角线和者斜对角线),然后会获得格子上的 数值(只能获取一 ...
- CodeForces463C Gargari and Bishops(贪心)
CodeForces463C Gargari and Bishops(贪心) CodeForces463C 题目大意: 在国际象棋的棋盘上放两个主教,这个两个主教不能攻击到同一个格子,最后的得分是这 ...
- B. Wet Shark and Bishops(思维)
B. Wet Shark and Bishops time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- Codeforces 612B. Wet Shark and Bishops 模拟
B. Wet Shark and Bishops time limit per test: 2 seconds memory limit per test: 256 megabytes input: ...
- Wet Shark and Bishops(思维)
Today, Wet Shark is given n bishops on a 1000 by 1000 grid. Both rows and columns of the grid are nu ...
- GYM - 101147 F.Bishops Alliance
题意: 一个n*n的棋盘,有m个主教.每个主教都有自己的权值p.给出一个值C,在棋盘中找到一个最大点集.这个点集中的点在同一条对角线上且对于点集中任意两点(i,j),i和j之间的主教数(包括i,j)不 ...
- codeforces 463C. Gargari and Bishops 解题报告
题目链接:http://codeforces.com/contest/463/problem/C 题目意思:要在一个 n * n 大小的棋盘上放置两个bishop,bishop可以攻击的所有位置是包括 ...
- Codeforces--621B--Wet Shark and Bishops(数学)
B. Wet Shark and Bishops time limit per test 2 seconds memory limit per test 256 megabytes input ...
- Bishops Alliance—— 最大上升子序列
原题链接:http://codeforces.com/gym/101147/problem/F 题意:n*n的棋盘,给m个主教的坐标及其私有距离p,以及常数C,求位于同一对角线上满足条件:dist(i ...
随机推荐
- bzoj 3931 [CQOI2015]网络吞吐量(最短路,最大流)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3931 [题意] 只能通过1-n的最短路,求网络最大流 [思路] 分别以1,n为起点做最 ...
- ubuntu使用问题与解决记录[持续更新]
1. 添加到计划任务 为脚本增加可执行权限 sudo chmod +x yeelink.sh 将脚本加入cronjob(计划任务) sudo crontab -e 在cornjob文件中添加下面一行, ...
- uva202:循环小数(循环节+抽屉原理)
题意: 给出两个数n,m,0<=n,m<=3000,输出n/m的循环小数表示以及循环节长度. 思路: 设立一个r[]数组记录循环小数,u[]记录每次的count,用于标记,小数计算可用 r ...
- 现代程序设计homework-06
现代程序设计homework-06 1) 把程序编译通过, 跑起来. 加入了倒退的功能,程序已经能跑起来了(见代码). 不过倒退功能有些bug,不过这是由于原本程序的主逻辑就有点问题(对于不可走的格子 ...
- 模板引擎:Velocity&FreeMarker(转)
Velocity,名称字面翻译为:速度.速率.迅速,用在Web开发里,用过的人可能不多,大都基本知道和在使用Struts,到底Velocity和Struts(Taglib和Tiles)是如何联系?在技 ...
- bashrc的加载
无意中将home下的所有文件都删除了,一些配置文件都丢了. 重新登陆后,发现无法加载bashrc. 查找后,发现问题不在于bashrc,而在与.bash_profile丢失 login shell m ...
- Ubuntu 下安装 Oracle Java
这只是一篇流水帐,记录如何安装Java. 在Ubuntu 下管理软件很方便,但安装的Java是opensdk.如果在某些条件下,需要安装Sun (Oracle)的Java,则需要自己手工安装. 一般情 ...
- js正则验证手机号
var regp = /^(\+86|86|)1[3458][0-9]{9}$/; if(str==""){ var flag = checkstatus(obj,"&q ...
- Java学习笔记(一):数据类型与变量
数据类型 Java中存在2种数据类型,下面我们来详解一下: 基本数据类型: 引用数据类型: 可以用一张表来记录: 基本数据类型 整型 byte:1个字节8位,取值范围为:[-128, 127],直接写 ...
- INV(库存管理)
物料 PROCEDURE update_item(p_init_msg_list IN VARCHAR2 DEFAULT fnd_api.g_false, x_return_status OUT NO ...