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 ...
随机推荐
- android相关文件夹的存取方式与函数解析---全
因为排版问题.转为markdown编辑: http://blog.csdn.net/self_study/article/details/58587412
- 【Sprint2 每日Scrum】 第一天(4.22)Sprint2计划会议成果
Sprint2计划会议成果 从今天起我们就开始正式的Sprint2之旅了,经过上一次Sprint1的冲刺计划和几天的调整,我们已经大致了解了敏捷开发的流程和思想,并将我们的TD学生助手做出了大致的框架 ...
- Cadence SPB 16. 6 安装步骤
1.首先下载Cadence Allegro SPB orCAD16. 6 安装包,单击我,下载之后运行其中的setup.exe,然后先安装第一项License Manager
- idea设置提示不区分大小写
- Codeforces Round #267 (Div. 2) B. Fedor and New Game
After you had helped George and Alex to move in the dorm, they went to help their friend Fedor play ...
- kubectl技巧之查看资源列表,资源版本和资源schema配置
系列目录 在kubernetes里,pod,service,rs,rc,deploy,resource等对象都需要使用yaml文件来创建,很多时候我们都是参照照官方示例或者一些第三方示例来编写yaml ...
- Codeforces Round #243 (Div. 1)——Sereja and Squares
题目链接 题意: 给n个点,求能组成的正方形的个数. 四边均平行与坐标轴 大神的分析: 经典题 我们考虑每一种x坐标,显然仅仅有<= sqrt{N}个x坐标出现了> sqrt{N}次,我们 ...
- Android组件系列----ContentProvider内容提供者【4】
(4)单元測试类: 这里须要涉及到另外一个知识:ContentResolver内容訪问者. 要想訪问ContentProvider.则必须使用ContentResolver. 能够通过ContentR ...
- JMeter中使用Put请求方式请求接口
前言 现在有如下接口,是以PUT的方式请求的: 请求URL:IP+Port+/api/v1/apps/{appId} 请求参数: 参数名 必选 类型 nameCn 是 string nameEn 是 ...
- iOS开发---- 开发错误汇总及解决方法
本文转载至 http://blog.csdn.net/shenjx1225/article/details/8561695 一.今天调试程序的时候,出现了一个崩溃,信息如下: 2013-02-01 0 ...