Bishops
题意:
给定一个 $n*n$ 的国际棋盘,求问在上面放 $K$ 个象的方案数。
解法:
首先可以发现黑格和白格互不干扰,这样我们可以将黑格,白格分别求出。
考虑 $f(i,j)$ 表示坐标化后考虑长度为 $i,i-2,i-4,...$ 的 $y=x$ 斜线,放了 $j$ 个棋子的方案数。
这样有
$$f(i,j) = f(i-2,j) + 2(i-j+1)f(i-2,j-1) + (i-j+2)(i-j+1)f(i-2,j-2) , i<n$$
$$f(i,j) = f(i-2,j) + (i-j+1)f(i-2,j-1), j = n$$
$$ans = \sum_{i=0}^K{f(n,i) \cdot f(n-1,K-i)}$$
#include <bits/stdc++.h> #define LL unsigned long long const int N = ; using namespace std; int n,K;
LL f[N][N*N]; int main()
{
while(scanf("%d%d",&n,&K),n||K)
{
if(n==)
{
cout<<<<endl;
continue;
}
memset(f,,sizeof(f));
f[][] = ;
f[][] = ;
f[][] = ;
for(int i=;i<=n;i++)
for(int j=;j<=i;j++)
{
f[i][j] = f[i-][j];
if(j>=)
{
if(i<n)
{
f[i][j] += f[i-][j-] * 2LL * (i-j+1LL);
f[i][j] += f[i-][j-] * (i-j+2LL)*(i-j+1LL);
}
else f[i][j] += f[i-][j-] * (i-j+1LL);
}
}
LL ans = ;
for(int i=;i<=K;i++)
ans += f[n][i] * f[n-][K-i];
cout << ans << endl;
}
return ;
}
Bishops的更多相关文章
- codeforces Gargari and Bishops(很好的暴力)
/* 题意:给你一个n*n的格子,每一个格子都有一个数值!将两只bishops放在某一个格子上, 每一个bishop可以攻击对角线上的格子(主对角线和者斜对角线),然后会获得格子上的 数值(只能获取一 ...
- Little Bishops uva861
Little Bishops A bishop is a piece used in the game of chess which is played on a board of square gr ...
- 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 ...
随机推荐
- iOS 倒计时NSTimer
项目中可能会遇到有些倒计时的地方 比方 手机验证的时候,验证码一般都会有一个时间限制,此时在输入验证码的地方就须要展示一个倒计时 详细实现方式是使用了iOS 自带的 NSTimer 上代码 首先新建 ...
- rf-demos (request)
*** Settings *** Library RequestsLibrary Library Collections Library XML *** Test Cases *** case1 Cr ...
- hdu 5316 Magician 线段树
链接:http://acm.hdu.edu.cn/showproblem.php? pid=5316 Magician Time Limit: 18000/9000 MS (Java/Others) ...
- ORCAD元件属性白色区域和黄色区域的理解
白色部分为instance属性,黄色部分为occurence 属性 在平坦式电路中,黄色部分是默认不显示的. 在层次式电路中,黄色部分会显示. 如果这两个区域的Reference不同,以黄色 ...
- canvas转盘抽奖的实现(二)
本篇是<canvas转盘抽奖的实现(一)>的另一种实现方法,主要通过css3的transform以及transition过渡来实现. // ' + r + '等奖'; } draw ...
- HDU 1247 Hat’s Words(字典树变形)
题目链接:pid=1247" target="_blank">http://acm.hdu.edu.cn/showproblem.php? pid=1247 Pro ...
- What the 80/20 Rule Tells Us about Reducing HTTP Requests
Performance Research, Part 1: What the 80/20 Rule Tells Us about Reducing HTTP Requests https://yuib ...
- 电脑插入U盘后显示CD驱动器,如何还原为正常U盘?
以前用电脑店制作U盘启动工具,结果U盘的一小部分变成了CD驱动器, 无论怎么格式化都无法将U盘还原,这几天心血来潮,看了一些恢复U盘的教程, 打算写一篇博客讲解一下还原过程(本人亲测) 1.下载Chi ...
- MFC获取电脑硬盘序列号(附源代码)
在新建的project里面加入一个类 即:下面一个类 GetHDSerial.cpp <code class="hljs cs has-numbering" style= ...
- mongodb学习之:副本集
前面一张介绍了主从模式,现在mongoDB官方已经不建议使用主从模式了,替代方案是采用副本集的模式.副本集不能在一台电脑上操作.需要准备3台电脑进行搭建.副本集就是mongoDB副本所组成的一个集群. ...