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 ...
随机推荐
- 【恒天云技术分享系列10】OpenStack块存储技术
原文:http://www.hengtianyun.com/download-show-id-101.html 块存储,简单来说就是提供了块设备存储的接口.用户需要把块存储卷附加到虚拟机(或者裸机)上 ...
- Xcode 4 插件制作入门
转自:http://www.onevcat.com/2013/02/xcode-plugin/ 2014.5.4更新 对于 Xcode 5,本文有些地方显得过时了.Xcode 5 现在已经全面转向了 ...
- Android实例-手机震动(XE8+小米2)
相关资料:http://blog.csdn.net/laorenshen/article/details/41148843 结果: 1.打开Vibrate权限为True. 2.规律震动我没感觉出来,有 ...
- CodeForces 176B Word Cut (计数DP)
Word Cut Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit St ...
- POJ 1502 MPI Maelstrom(最短路)
MPI Maelstrom Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4017 Accepted: 2412 Des ...
- Spring EL method invocation example
In Spring EL, you can reference a bean, and nested properties using a 'dot (.)' symbol. For example, ...
- 通过源码学Java基础:InputStream、OutputStream、FileInputStream和FileOutputStream
1. InputStream 1.1 说明 InputStream是一个抽象类,具体来讲: This abstract class is the superclass of all classes r ...
- codeforces 631A Interview
A. Interview time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- BestCoder Round #69 (div.2)(hdu5611)
Baby Ming and phone number Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Ja ...
- Java学习笔记(三):数组
数组声明 java语言中,数组是一种最简单的复合数据类型.数组是有序数据的集合,数组中的每个元素具有相同的数据类型,可以用一个统一的数组名和下标来唯一地确定数组中的元素. int arr1[]; in ...