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 ...
随机推荐
- 在mac上截屏的几种方式
方法 1: 对屏幕的一部分进行截图 按下Command+Shift+4 方法 2: 对整个屏幕进行截图 按下Command+Shift+3 方法 3: 把截图保存到粘贴板 按下Command+ ...
- 《java数据结构与算法》系列之“开篇”
大学的时候学习数据结构,当时吧虽然没挂这门课,但是确实学的不咋地,再但是其实自己一直都觉得数据结构很重要,是基础,只有基础好了,后面的路才能走的更好. 懒惰真的是天下的罪恶之源.所以一直到现在都毕业了 ...
- 复习java基础第六天(IO)
一:File 类 • 输入:读取外部数据(磁盘.光盘等存储设备的数据)到程序(内存)中. • 输出:将程序(内存)数据输出到磁盘.光盘等存储设备中 • Java 的 IO 流主要包括输入.输出两种 ...
- MFC和OpenCV结合
最重要的一点:如何把OpenCV的框嵌入MFC的ID.. 把cv显示框嵌入 pic控件 cvNamedWindow("kalman"); HWND hWnd = (HWND) cv ...
- java中的位运算及移位运算
为了方便对二进制位进行操作,Java给我们提供了以下四个二进制位操作符: & 按位与 | 按位或 ^ 按位异或 ~ 按位取反 Java中有三个移位运算符: 左移:&l ...
- GDI 画刷(10)
创建画刷 调用 CreateSoildBrush.CreateHatchBrush.CreateBrushIndirect 函数可以创建画刷. CreateSoildBrush:创建实心画刷: Cre ...
- stylus解决移动端1像素线等问题
引用了yo框架中的_border.scss(用来获取yo框架封装的border) 以及 variables.scss(用来获取媒体查询的规则) border($border-width = 1 ...
- 第1章 面向对象的JavaScript
针对基础知识的每一个小点,我都写了一些小例子,https://github.com/huyanluanyu1989/DesignPatterns.git,便于大家理解,如有疑问,大家可留言给我,最近工 ...
- [tyvj1957 Poetize5] Vani和Cl2捉迷藏 (最小路径可重点覆盖+二分图最大匹配)
传送门 Description 这片树林里有N座房子,M条有向道路,组成了一张有向无环图. 树林里的树非常茂密,足以遮挡视线,但是沿着道路望去,却是视野开阔.如果从房子A沿着路走下去能够到达B,那么在 ...
- 调用的方法里接收一个List<>类型的参数,里面是自定义的EC类, 我要通过反射构建这List对象
public static object CreateGeneric(Type generic, Type innerType, params object[] args) ...