lightoj Rooks 1005 (棋盘放车问题) (数学规律)
来源:互联网 发布:后期软件 油画质感 编辑:程序博客网 时间:2024/05/05 02:38
1005 - Rooks
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
Output for Sample Input
8
1 1
2 1
3 1
4 1
4 2
4 3
4 4
4 5
Case 1: 1
Case 2: 4
Case 3: 9
Case 4: 16
Case 5: 72
Case 6: 96
Case 7: 24
Case 8: 0
//题意:给你n*n的棋盘,m个棋子,问有多少种排法。
#include<stdio.h>#include<string.h>#include<algorithm>#define ll long longusing namespace std;int main(){int t;int T=1;ll n,m,i;ll sum,num,s;scanf("%d",&t);while(t--){sum=num=1;scanf("%lld%lld",&n,&m);printf("Case %d: ",T++);if(n<m)printf("0\n");else{for(i=n;i>n-m;i--)sum*=i;for(i=1;i<=m;i++)num*=i;s=sum*(sum/num);printf("%lld\n",s);}}return 0;}
- lightoj Rooks 1005 (棋盘放车问题) (数学规律)
- LightOJ 1005 - Rooks (dp、组合数学)
- lightoj 1005 - Rooks(组合数学)
- LightOJ 1005 - Rooks (组合数学dp模拟)
- LightOJ 1005 - Rooks(DP)
- LightOJ - 1005 Rooks(统计)
- LightOJ 1005 - Rooks(计数)
- lightoj 1005 - Rooks 【组合数学】
- lightoj 1005 - Rooks 【组合数学】
- LightOJ-1005-Rooks [组合数学]
- lightoj--1005--Rooks(组合数)
- Lightoj 1005 - Rooks (概率选取)
- lightoj 1005 ROOKS(组合数)
- light oj 1005 - Rooks (组合数学)
- LightOJ 1005 Rooks 动态规划dp || 组合数学
- LightOJ 1005 - Rooks
- LightOJ 1005 - Rooks
- lightoj 1005 Rooks
- Struts2上传文件
- android WebView总结
- 编译原理中的正规表达式转NFA
- Duplicate application configs: <dubbo:application错误
- iOS——LLVM、Clang浅析
- lightoj Rooks 1005 (棋盘放车问题) (数学规律)
- AutoCompleteTextView and MultiAutoCompleteTextView
- WebGL之ThreeJS学习之旅01
- 欧拉回路
- 浅谈RMI
- 中位数 21% 通过 给定一个未排序的整数数组,找到其中位数。 中位数是排序后数组的中间值,如果数组的个数是偶数个,则返回排序后数组的第N/2个数
- 【多线程】ScheduledThreadPoolExecutor的scheduleAtFixedRate方法探究
- Linux集合
- linux下杀死进程的几种方法