lightoj--1005--Rooks(组合数)
| Time Limit: 1000MS | Memory Limit: 32768KB | 64bit IO Format: %lld & %llu |
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
/*以前做组合数总是错,总算找到一种神器#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(组合数)的更多相关文章
- 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 ...
- 1005 - Rooks(规律)
1005 - Rooks PDF (English) Statistics Forum Time Limit: 1 second(s) Memory Limit: 32 MB A rook is ...
- Rooks LightOJ - 1005
https://vjudge.net/problem/LightOJ-1005 题意:在n*n的矩形上放k个车,使得它们不能互相攻击,求方案数. ans[i][j]表示在i*i的矩形上放j个车的方案数 ...
- Light oj 1005 - Rooks (找规律)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1005 纸上画一下,找了一下规律,Ank*Cnk. //#pragma comm ...
- lightoj 1005 组合数学
题目链接:http://lightoj.com/volume_showproblem.php?problem=1005 #include <cstdio> #include <cst ...
- Light OJ 1005 - Rooks 数学题解
版权声明:本文作者靖心.靖空间地址:http://blog.csdn.net/kenden23/,未经本作者同意不得转载. https://blog.csdn.net/kenden23/article ...
- lightoj 1005
组合数学,ans = C(n,k)*A(n,k). #include<cstdio> #include<string> #include<cstring> #inc ...
- Light OJ 1005 - Rooks(DP)
题目大意: 给你一个N和K要求确定有多少种放法,使得没有两个车在一条线上. N*N的矩阵, 有K个棋子. 题目分析: 我是用DP来写的,关于子结构的考虑是这样的. 假设第n*n的矩阵放k个棋子那么,这 ...
- Light OJ Dynamic Programming
免费做一样新 1004 - Monkey Banana Problem 号码塔 1005 - Rooks 排列 1013 - Love Calculator LCS变形 dp[i][j][k]对于第一 ...
- (light OJ 1005) Rooks dp
http://www.lightoj.com/volume_showproblem.php?problem=1005 PDF (English) Statistics Forum Tim ...
随机推荐
- 5.14JDBC
一.##JDBC 1. 概念:Java DataBase Connectivity Java 数据库连接, Java语言操作数据库. JDBC本质:其实是官方(sun公司)定义的一套操作所有关系型数 ...
- IBMWebsphere 使用jar包删除文件
1. 先使用ant打包一个jar包,删除其他不要的目录和文件,仅保留一个空的xxx.war文件夹("xxx"对应was上的工程安装根目录) 2. 在文件夹下新建一个META-INF ...
- 在Winform中怎么实现图片的旋转,比如说实现仪表盘功能,看代码吧,看太不懂的欢迎问
; //旋转的角度 //Timer定时器 private void timer1_Tick(object sender, EventArgs e) { timer1.Enabled = false; ...
- Django中的bug总结
1.插入数据库的时候,少写一个字段.ps:看准数据库的字段,是不是非空,是不是外键. 2.当同一个视图中需要连续操作两个数据表时,先看好两个表的外键之间的关系,再进行操作表.比如:一个订单表order ...
- 深入浅出java多态
所谓多态就是指程序中定义的引用变量所指向的具体类型和通过该引用变量发出的方法调用在编程时并不确定,而是在程序运行期间才确定,即一个引用变量倒底会指向哪个类的实例对象,该引用变量发出的方法调用到底是哪个 ...
- MacOS 升级后pod 出现的问题
-bash: /usr/local/bin/pod: /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby: bad ...
- 【原创】python中文编码问题深入分析(三):python2.7文件读写中文编码问题
上一篇文章介绍和分析了python2.7中使用print遇到的中文编码问题的原因和解决方案,本篇主要介绍一下python2.7中执行文件读写可能遇到的编码问题. 1.文件读取 假如我们读取一个文件,文 ...
- Object::connect: No such slot (QT槽丢失问题)
1.看看你的类声明中有没有Q_OBJECT,并继承public QMainWindow{ 例如: class CPlot: public QMainWindow{ Q_OBJECT 2.你声明的函数要 ...
- .Net Core 中X509Certificate2 私钥保存为 pem 的方法
在自己签发CA证书和颁发X509证书时,私钥通过下面的方法保存为PEM 相关代码可以已经提交在了 https://github.com/q2g/q2g-helper-pem-nuget/pull/13 ...
- DD打卡
一.安装逍遥安卓模拟器 二.安装钉钉 三.设置当前GPS座标 位置模拟器: 链接: https://pan.baidu.com/s/1TC5QkrGAgHOJWtzJnX6vhA 提取码: bpu8 ...