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. Java 开源博客 Solo 1.2.0 发布 - 一键启动

    Solo 1.2.0 正式发布了,感谢一直以来关注 B3log 开源的朋友! 在这个版本中,我们引入了一个新的特性 -- 独立模式: 不需要安装数据库.Servlet 容器 只需要安装好 Java 环 ...

  2. 设置Hadoop的 dataNode的单个Map的内存配置

    1.进入hadoop的配置目录 ,找到 环境变量的 $HADOOP_HOME cd $HADOOP_HOME 2.修改dataNode 节点的 单个map的能使用的内存配置 找到配置的文件: /opt ...

  3. CDC之Metastability

    1 CDC  A clock domain crossing occurs whenever data is transferred from a flop driven by one clock t ...

  4. dubbo之集群容错

    在集群调用失败时,Dubbo 提供了多种容错方案,缺省为 failover 重试. 集群容错模式 1. Failover Cluster 失败自动切换,当出现失败,重试其它服务器 .通常用于读操作,但 ...

  5. 【sqli-labs】 less1 GET - Error based - Single quotes - String(GET型基于错误的单引号字符型注入)

    GET方式提交id参数 添加单引号,出现报错,爆出数据库名称和部分SQL语句 http://localhost/sqli/Less-1/?id=1' 使用order by猜测字段数,用#注释掉后面li ...

  6. sql server time(7) 默认值

    语句为 ALTER TABLE dbo.YourTable ADD CONSTRAINT DF_TimeDefault DEFAULT '00:00:00' FOR YourTimeColumn 比如 ...

  7. java将父类所有的属性COPY到子类中

    public class FatherToChildUtils { /* * 将父类所有的属性COPY到子类中. * 类定义中child一定要extends father: * 而且child和fat ...

  8. 【Leetcode】【简单】【682棒球比赛】【JavaScript】

    题目 682. 棒球比赛 你现在是棒球比赛记录员.给定一个字符串列表,每个字符串可以是以下四种类型之一:1.整数(一轮的得分):直接表示您在本轮中获得的积分数.2. "+"(一轮的 ...

  9. [luogu4162 SCOI2009] 最长距离(最短路)

    传送门 Solution 题目是最长路,其实是最短路ヽ(ー_ー)ノ 把进入障碍点的边设为1,其他为0.枚举每个点为起点找距离<=T的点,更新答案 Code //By Menteur_Hxy #i ...

  10. Firefly-rk3399 开发板环境搭建

    Firefly教程网站:http://wiki.t-firefly.com/zh_CN/Firefly-RK3399/started.html 系统烧录: http://wiki.t-firefly. ...