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 ...
随机推荐
- [转]Java web 开发 获取用户ip
如果通过了多级反向代理的话,X-Forwarded-For的值并不止一个,而是一串IP值,那么真正的用户端的真实IP则是取X-Forwarded-For中第一个非unknown的有效IP字符串. pu ...
- 【Oracle】OGG(Oracle GoldenGate)简介及搭建过程
GoldenGate公司简介 GoldenGate公司专注于数据同步领域,是实现数据同步技术的领导者.至2007年,在全球35个国家售出超过2000个许可证,客户分布在政府.银行.电信.证券.传媒.医 ...
- postgreSQL中跨库查询在windows下的实现方法
以下是在postgreSQL 8.1版本中的实践,其他版本类似: 1.将C:\Program Files\PostgreSQL\8.1\share\contrib下的dblink.sql复制到C:\P ...
- Windows-Server-2008、IIS7.0环境下配置伪静态化
在Windows-Server-2008.IIS7.0环境下配置伪静态化 首先,是IIS7.0的配置,由于Windows Server 2008操作系统默认的IIS版本为 ...
- MySQL在Linux下的表名如何不区分大小写
MySQL在Linux下的表名如何不区分大小写 今天测试的时候,遇到一些问题,明明看到数据,就是查不出来;后来发现,在linux下, mysql的表名区分大小写,而在windows下是不区分,从w ...
- BZOJ 1572: [Usaco2009 Open]工作安排Job 贪心 + 堆 + 反悔
Description Farmer John想修理牧场栅栏的某些小段.为此,他需要N(1<=N<=20,000)块特定长度的木板,第i块木板的长度为Li(1<=Li<=50, ...
- 【剑指Offer】23、二叉搜索树的后序遍历序列
题目描述: 输入一个整数数组,判断该数组是不是某二叉搜索树的后序遍历的结果.如果是则输出Yes,否则输出No.假设输入的数组的任意两个数字都互不相同. 解题思路: 对于后续遍历序列,序 ...
- ios开发——runtime
首先,最重要的一点,学runtime能干嘛? 1.使用runtime改变变量值 2.使用runtime交换方法 3.使用runtime添加方法 4.使用runtime给分类扩展属性 学了runtime ...
- ArchLinux简单介绍
一.Archlinux的由来 2002年由加拿大的Judd Vinet,Archlinux的创始人 怀着对Debian.Redhat的包管理器不满,于是创建了Archlinux!目前ArchLinux ...
- 洛谷P1208 [USACO1.3]混合牛奶 Mixing Milk【贪心+背包】
由于乳制品产业利润很低,所以降低原材料(牛奶)价格就变得十分重要.帮助Marry乳业找到最优的牛奶采购方案. Marry乳业从一些奶农手中采购牛奶,并且每一位奶农为乳制品加工企业提供的价格是不同的.此 ...