HDU 5794 A Simple Chess (lucas定理+费马小定理)

12 篇文章 0 订阅
4 篇文章 0 订阅

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  (x2x1)2+(y2y1)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,(1n,m1018,0r100) , 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(1xn,1ym) , 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) 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值