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 ...
随机推荐
- MFC特定函数的应用20160720(SystemParametersInfo,GetWindowRect,WriteProfileString,GetSystemMetrics)
1.SystemParametersInfo函数可以获取和设置数量众多的windows系统参数 MFC中可以用 SystemParametersInfo(……) 函数来获取和设置系统信息,如下面例子所 ...
- Python之Tkinter模块学习
本文转载自:http://www.cnblogs.com/kaituorensheng/p/3287652.html Tkinter模块("Tk 接口")是Python的标准Tk ...
- Navicate
快捷键 1.ctrl+q 打开查询窗口 2.ctrl+/ 注释sql语句 3.ctrl+shift +/ 解除注释 4.ctrl+r 运行查询窗口的sql语句 5.ctrl+shift+r 只运行选中 ...
- “大数据讲师”、“Hadoop讲师”、“Spark讲师”、“云计算讲师”、“Android讲师”
王家林简介 Spark亚太研究院院长和首席专家,中国目前唯一的移动互联网和云计算大数据集大成者. 在Spark.Hadoop.Android等方面有丰富的源码.实务和性能优化经验.彻底研究了Spark ...
- Navicat 远程连接SQL Server 2014 Express 报08001错误
场景:Navicat 远程连接SQL Server 2014 Express 报08001错误,经查验防火墙端口1434,1433已经打开 过程:1. 一开始觉得是连接名称问题,使用IP地址或者主机名 ...
- 转】Nginx+tomcat集群环境搭建(Windows下)
原博文出自于: http://blog.csdn.net/clj198606061111/article/details/22621003 感谢! 实验环境 windows xp s ...
- Android View事件传递机制
ViewGroup dispatchTouchEvent onInterceptTouchEvent onTouch View dispatchTouchEvent onTouch 假设View的层级 ...
- centos 使用mutt 命令发送邮件,随笔非教程
#按照mutt yum -y install mutt #发送邮件 echo .com -s "邮件主题" -a 附件本地地址
- poj 3180 The Cow Prom(强联通分量)
http://poj.org/problem?id=3180 The Cow Prom Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
- nyoj 127 星际之门(一)
星际之门(一) 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 公元3000年,子虚帝国统领着N个星系,原先它们是靠近光束飞船来进行旅行的,近来,X博士发明了星际之门 ...