Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %lld & %llu

Submit
Status

Description

A rook is a piece used in the game of chess which is played on a board of square grids. A rook can only move vertically or horizontally from its current position and two rooks attack each other if one is on the path of the other. In the following figure,
the dark squares represent the reachable locations for rook R1 from its current position. The figure also shows that the rook
R1 and R2 are in attacking positions where
R1 and R3 are not.
R2
and R3 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 rooks on an n x n chessboard so that no two of them are in attacking positions.

Input

Input starts with an integer T (≤ 350), denoting the number of test cases.

Each case contains two integers n (1 ≤ n ≤ 30) and k (0 ≤ k ≤ n2).

Output

For each case, print the case number and total number of ways one can put the given number of rooks 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
1017.

Sample Input

8

1 1

2 1

3 1

4 1

4 2

4 3

4 4

4 5

Sample Output

Case 1: 1

Case 2: 4

Case 3: 9

Case 4: 16

Case 5: 72

Case 6: 96

Case 7: 24

Case 8: 0

Source

Problem Setter: Jane Alam Jan

Submit
Status

/*以前做组合数总是错,总算找到一种神器#include<stdio.h>
#include<string.h>
typedef long long LL;
LL c[33][33];
int main()
{
int t;
scanf("%d",&t);
int Case=1;
for(int i=1;i<=30;i++)
{
c[i][0]=c[i][i]=1;
c[i][1]=i;
for(int j=2;j<i;j++)
{
c[i][j]=c[i-1][j]+c[i-1][j-1];
}
}
while(t--)
{
int n,k;
LL sum;
scanf("%d%d",&n,&k);
if(n<k)
{
printf("Case %d: 0\n",Case++);
}
else
{
sum=c[n][k]*c[n][k];
for(int i=1;i<=k;i++)
sum*=i;
printf("Case %d: %lld\n",Case++,sum);
}
}
}

lightoj--1005--Rooks(组合数)的更多相关文章

  1. Lightoj 1005 Rooks(DP)

    A rook is a piece used in the game of chess which is played on a board of square grids. A rook can o ...

  2. 1005 - Rooks(规律)

    1005 - Rooks   PDF (English) Statistics Forum Time Limit: 1 second(s) Memory Limit: 32 MB A rook is ...

  3. Rooks LightOJ - 1005

    https://vjudge.net/problem/LightOJ-1005 题意:在n*n的矩形上放k个车,使得它们不能互相攻击,求方案数. ans[i][j]表示在i*i的矩形上放j个车的方案数 ...

  4. Light oj 1005 - Rooks (找规律)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1005 纸上画一下,找了一下规律,Ank*Cnk. //#pragma comm ...

  5. lightoj 1005 组合数学

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1005 #include <cstdio> #include <cst ...

  6. Light OJ 1005 - Rooks 数学题解

    版权声明:本文作者靖心.靖空间地址:http://blog.csdn.net/kenden23/,未经本作者同意不得转载. https://blog.csdn.net/kenden23/article ...

  7. lightoj 1005

    组合数学,ans = C(n,k)*A(n,k). #include<cstdio> #include<string> #include<cstring> #inc ...

  8. Light OJ 1005 - Rooks(DP)

    题目大意: 给你一个N和K要求确定有多少种放法,使得没有两个车在一条线上. N*N的矩阵, 有K个棋子. 题目分析: 我是用DP来写的,关于子结构的考虑是这样的. 假设第n*n的矩阵放k个棋子那么,这 ...

  9. Light OJ Dynamic Programming

    免费做一样新 1004 - Monkey Banana Problem 号码塔 1005 - Rooks 排列 1013 - Love Calculator LCS变形 dp[i][j][k]对于第一 ...

  10. (light OJ 1005) Rooks dp

    http://www.lightoj.com/volume_showproblem.php?problem=1005        PDF (English) Statistics Forum Tim ...

随机推荐

  1. ES6 arrow function

    语法: () => { … } // 零个参数用 () 表示: x => { … } // 一个参数可以省略 (): (x, y) => { … } // 多参数不能省略 (): 当 ...

  2. [hihocoder][Offer收割]编程练习赛59

    替换函数 #pragma comment(linker, "/STACK:102400000,102400000") #include<stdio.h> #includ ...

  3. CSS3 3D变换实例 滚动的正方体

    笔记: 2D变换 transform 位移   translateX() translateY()  简写:translate(X值,Y值)  正值向右,负值向左 旋转 rotate()  rotat ...

  4. SQL Server 置疑、可疑、正在恢复

    一.出错情况 有些时候当你重启了数据库服务,会发现有些数据库变成了正在恢复.置疑.可疑等情况,这个时候DBA就会很紧张了,下面是一些在实践中得到证明的方法. 在一次重启数据库服务后,数据库显示正在恢复 ...

  5. ★Java语法(一)——————————标识符

    1.定义:用来标识类名.变量名.方法名.数组名.文件名的有效字符序列: 2.命名规则:a 由字母.数字._(下划线)和$(美元符号)组成 b 数字不能作为第一个字符 c 不能是Java中的关键字和保留 ...

  6. 经典实用SQL Server语句大全总结(一)

    简要介绍基础语句:1.说明:创建数据库CREATE DATABASE database-name2.说明:删除数据库drop database dbname3.说明:备份sql server--- 创 ...

  7. 数据库操作(一)DML

    1.数据库 数据库可视为电子化的文件柜——存储电子文件的处所,用户可以对文件中的数据进行新增.查询.更新.删除等操作. 所谓“数据库”是以一定方式储存在一起.能与多个用户共享.具有尽可能小的冗余度.与 ...

  8. java HttpURLConnection 登录网站 完整代码

    import java.io.*; import java.util.*; import java.net.*; public class WebTest { public static void m ...

  9. NW.js构建PC收银端安装程序的指南

    1.首先下载nw.js的SDK: https://nwjs.org.cn/download.html 2.SDK目录下新建myapp文件夹: 3.myapp文件夹内新建package.json文件: ...

  10. pymysql.err.ProgrammingError: (1064)(字符串转译问题)

    代码: sql = "insert into dm_copy(演出类型,演出场馆,剧目名称,演出地点,演出时间,演出票价,演出团体,创建时间, url)values('%s','%s','% ...