题意:

给定一个 $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. linux 下weblogic启动和停止

    启动weblogic 本例中weblogic 安装路径为:/data/weblogic/wls/wlserver_10.3/ 1. 启动nodeManager cd /data/weblogic/wl ...

  2. DDR 布线规则

    https://blog.csdn.net/cpf099/article/details/52038862 https://blog.csdn.net/cpf099/article/details/5 ...

  3. java对象访问

    下面这句代码: Object obj = new Object(); 对象引用在栈中,对象实体存在堆中,引用的方式有两种,分别是通过句柄访问对象和通过直接指针访问对象. Sun HotSpot使用第二 ...

  4. 【BZOJ1844/2210】Pku1379 Run Away 模拟退火

    [BZOJ1844/2210]Pku1379 Run Away 题意:矩形区域中有一堆点,求矩形中一个位置使得它到所有点的距离的最小值最大. 题解:模拟退火的裸题,再调调调调调参就行了~ #inclu ...

  5. github for unity

  6. Dockder的CS模式:

    Docker的守护进程一直运行, yw1989@ubuntu:~$ ps -ef | grep docker : 就是docxker的守护进程 root : ? :: /usr/bin/dockerd ...

  7. sendevent是使用

    按下: sendevent /dev/input/event4 1 254 1 sendevent /dev/input/event4 0 0 0 松开: sendevent /dev/input/e ...

  8. UVA11752 The Super Powers —— 数论、枚举技巧

    题目链接:https://vjudge.net/problem/UVA-11752 题意: 一个超级数是能够至少能表示为两个数的幂,求1~2^64-1内的超级数. 题解: 1.可知对于 n = a^b ...

  9. HDU6025 Coprime Sequence —— 前缀和 & 后缀和

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6025 Coprime Sequence Time Limit: 2000/1000 MS (Java/ ...

  10. Gym - 100283K K. Cubes Shuffling —— 贪心

    题目链接:http://codeforces.com/gym/100283/problem/K 题解: 要使其相邻两项的差值之和最小,那么越靠中间,其数值越小. 那么剩下的问题就是如何放数字了.一开始 ...