题意:

给定一个 $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的更多相关文章

  1. codeforces Gargari and Bishops(很好的暴力)

    /* 题意:给你一个n*n的格子,每一个格子都有一个数值!将两只bishops放在某一个格子上, 每一个bishop可以攻击对角线上的格子(主对角线和者斜对角线),然后会获得格子上的 数值(只能获取一 ...

  2. 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 ...

  3. CodeForces463C Gargari and Bishops(贪心)

    CodeForces463C Gargari and Bishops(贪心) CodeForces463C 题目大意:  在国际象棋的棋盘上放两个主教,这个两个主教不能攻击到同一个格子,最后的得分是这 ...

  4. B. Wet Shark and Bishops(思维)

    B. Wet Shark and Bishops time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  5. Codeforces 612B. Wet Shark and Bishops 模拟

    B. Wet Shark and Bishops time limit per test: 2 seconds memory limit per test: 256 megabytes input: ...

  6. 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 ...

  7. GYM - 101147 F.Bishops Alliance

    题意: 一个n*n的棋盘,有m个主教.每个主教都有自己的权值p.给出一个值C,在棋盘中找到一个最大点集.这个点集中的点在同一条对角线上且对于点集中任意两点(i,j),i和j之间的主教数(包括i,j)不 ...

  8. codeforces 463C. Gargari and Bishops 解题报告

    题目链接:http://codeforces.com/contest/463/problem/C 题目意思:要在一个 n * n 大小的棋盘上放置两个bishop,bishop可以攻击的所有位置是包括 ...

  9. Codeforces--621B--Wet Shark and Bishops(数学)

     B. Wet Shark and Bishops time limit per test 2 seconds memory limit per test 256 megabytes input ...

  10. Bishops Alliance—— 最大上升子序列

    原题链接:http://codeforces.com/gym/101147/problem/F 题意:n*n的棋盘,给m个主教的坐标及其私有距离p,以及常数C,求位于同一对角线上满足条件:dist(i ...

随机推荐

  1. enter键触发的函数

    enter键触发的函数示例: <input type="text" onkeydown="fun();"> function fun() { if( ...

  2. C语言关键字—-sizeof 、typedef、const、static、register、extern、#define

    关键字:sizeof .#define.typedef.const.static.register.extern sizeof 1. 作用:求数据所占得内存空间大小 2. 本质:求数据得类型所占的内存 ...

  3. bash 的环境配置文件

    http://www.cnblogs.com/ggjucheng/archive/2012/11/01/2750179.html bash 的环境配置文件 你是否会觉得奇怪,怎么我们什么动作都没有进行 ...

  4. C语言判断回文数

    #include<stdio.h> #include<stdlib.h> int main() { //1.得到这个数字 2.翻转 3.进行比较 4.如果相同 就输出 是 否则 ...

  5. UVA 10042 Smith Numbers(数论)

    Smith Numbers Background While skimming his phone directory in 1982, Albert Wilansky, a mathematicia ...

  6. Logistic Regression 笔记与理解

    Logistic Regression 笔记与理解 Logistic Regression Hypothesis 记为 H(theta) H(theta)=g(z) 当中g(z),是一个叫做Logis ...

  7. .NET 4.0 WCF WebConfig aspNetCompatibilityEnabled 属性

    近来被一个问题困扰了好久,好好的一个WCF后台服务,在发布机器上可用.在自己机器上没法跑起来. 一直提示兼容性问题,后来在网上找来解决方案,但问题依旧.没办法又从客户的服务器上重新把配置内容 拿下来审 ...

  8. php中屏蔽date的错误

    php中添加  date_default_timezone_set('asia/shanghai'); 可以屏蔽 <?php echo date('Y-m-d',$row3['time']); ...

  9. 高性能MySQL(三)

    服务器性能剖析 性能优化概述 性能优化是降低CPU使用率?错误,资源就是用来消耗的,新版本MySQL的InnoDB引擎对资源的利用率还增高了,所以这不是一个好的衡量标准. 提升每秒查询量?其实就是吞吐 ...

  10. 功能强大的Xcode辅助工具Faux Pas:帮你找到各种隐形的bug

    本文转载至 http://www.cocoachina.com/industry/20140804/9307.html Faux Pas(Beta版下载地址)是一个Xcode辅助工具,用以检查Xcod ...