HDU 5794 A Simple Chess (lucas定理+費馬小定理)
A Simple Chess
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2672 Accepted Submission(s): 713
Problem Description
There is a n×m board,
a chess want to go to the position
(n,m) from the position (1,1).
The chess is able to go to position (x2,y2) from the position (x1,y1), only and if only x1,y1,x2,y2 is satisfied that (x2−x1)2+(y2−y1)2=5, x2>x1, y2>y1.
Unfortunately, there are some obstacles on the board. And the chess never can stay on the grid where has a obstacle.
I want you to tell me, There are how may ways the chess can achieve its goal.
(n,m) from the position (1,1).
The chess is able to go to position (x2,y2) from the position (x1,y1), only and if only x1,y1,x2,y2 is satisfied that (x2−x1)2+(y2−y1)2=5, x2>x1, y2>y1.
Unfortunately, there are some obstacles on the board. And the chess never can stay on the grid where has a obstacle.
I want you to tell me, There are how may ways the chess can achieve its goal.
Input
The input consists of multiple test cases.
For each test case:
The first line is three integers, n,m,r,(1≤n,m≤1018,0≤r≤100), denoting the height of the board, the weight of the board, and the number of the obstacles on the board.
Then follow r lines, each lines have two integers, x,y(1≤x≤n,1≤y≤m), denoting the position of the obstacles. please note there aren't never a obstacles at position (1,1).
For each test case:
The first line is three integers, n,m,r,(1≤n,m≤1018,0≤r≤100), denoting the height of the board, the weight of the board, and the number of the obstacles on the board.
Then follow r lines, each lines have two integers, x,y(1≤x≤n,1≤y≤m), denoting the position of the obstacles. please note there aren't never a obstacles at position (1,1).
Output
For each test case,output a single line "Case #x: y", where x is the case number, starting from 1. And y is the answer after module 110119.
Sample Input
1 1 0
3 3 0
4 4 1
2 1
4 4 1
3 2
7 10 2
1 2
7 1
Sample Output
Case #1: 1
Case #2: 0
Case #3: 2
Case #4: 1
Case #5: 5
Author
UESTC
Source
不貼程式碼了,差不多照著打的。
公 式
c(m,n)=m!/((m-n)!*n!)
性質1
C(n,m)= C(n,n-m)
性質2
C(n,m)= C(n-1,m-1)+C(n-1,m)
Lucas(n,m,p)=c(n%p,m%p)*Lucas(n/p,m/p,p)
相關文章
- 盧卡斯定理(Lucas定理)
- 同構——費馬小定理
- 費馬小定理-期望dp
- Lucas(盧卡斯)定理
- 費馬定理
- [Lucas定理] 集合計數
- Lucas定理 & Catalan Number & 中國剩餘定理(CRT)
- bzoj 2982: combination(lucas定理模板)
- 費馬小定理 + 費馬大定理 + 勾股數的求解 + 快速冪 + 矩陣快速冪 【模板】矩陣
- HDU 4549 M斐波那契數列(矩陣快速冪+費馬小定理)矩陣
- 數論入門基礎(同餘定理/費馬小定理/擴充套件歐幾里德演算法/中國剩餘定理)套件演算法
- HDU 2973 YAPTCHA(威爾遜定理)APT
- “沒有免費的午餐”定理(NFL定理)
- BZOJ 2111 [ZJOI2010]Perm 排列計數:Tree dp + Lucas定理
- 【演算法學習筆記】組合數與 Lucas 定理演算法筆記
- 矩陣樹定理 BEST 定理矩陣
- 矩陣樹定理與BEST定理矩陣
- 第四章:高次冪之和與費馬大定理
- 主定理
- Coppersmith定理MIT
- 奈奎斯特定理與夏農定理
- 用Rolle中值定理證明Lagrange中值定理
- BEST 定理與矩陣樹定理的證明矩陣
- ACM-ICPC 2018 南京賽區網路預賽__K The Great Nim Game【博弈論+費馬小定理+DP】ACMGAM
- 介值定理
- 大數定理
- 尤拉定理
- 盧卡斯定理
- 尤拉五邊形數定理小記
- 泛函分析筆記(十四)Baire定理,Banach-Steinhaus定理泛函分析筆記AI
- 讓AI理解費馬大定理的證明,兩個月過去了,進展如何?AI
- 矩陣樹定理矩陣
- 貝葉斯定理
- Hall定理總結
- 二項式定理
- 算數基本定理
- 威爾遜定理
- 角谷定理-XDOJ