有一个无限大的矩形,初始时你在左上角(即第一行第一列),每次你都可以选择一个右下方格子,并瞬移过去(如从下图中的红色格子能直接瞬移到蓝色格子),求到第nn行第mm列的格子有几种方案,答案对10000000071000000007取模。

Input多组测试数据。

两个整数n,m(2≤n,m≤100000)n,m(2≤n,m≤100000)

Output一个整数表示答案Sample Input

4 5

Sample Output

10

卢卡斯定理解杨辉三角 杨辉三角第n行的m个数可表示为C(n-1,m-1)
Lucas定理是用来求 C(n,m) mod p,p为素数的值,用来解决大组合数求模是很有用的。最大的数据处理能力是p在10^5左右。
C(n,m) = C(n-1,m-1) + C(n-1,m).

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define ll long long
const ll mod=1000000007;
#define maxn 70
ll pow(ll a,ll n,ll mod)
{
ll base=a,ret=1;
while(n)
{
if(n&1) ret=(ret*base)%mod;
base=(base*base)%mod;
n>>=1;
}
return ret%mod;
}
ll C(ll n,ll k,ll p)
{
if(k==n)
return 1;
if(n-k<k)
k=n-k;
ll ans=1;
for(ll i=1;i<=k;i++)
{
ans=ans*(n-i+1)%p*pow(i,mod-2,p)%p;
}
return ans;
}
ll lucas(ll n,ll m,ll p)
{
if(m==0)
return 1;
return C(n%p,m%p,p)*lucas(n/p,m/p,p)%p;
} int main()
{
ll n,m;
while(~scanf("%lld%lld",&n,&m))
{
cout<<lucas(m+n-4,m-2,mod)<<endl;
}
}

  

hdu_5698_瞬间移动的更多相关文章

  1. 51nod1627 瞬间移动

    打表可以看出来是组合数...妈呀为什么弄成n+m-4,n-1,m-3就错啊... //打表可以看出来是组合数...妈呀为什么弄成n+m-4,n-1,m-3就错啊... #include<cstd ...

  2. hdu-5698 瞬间移动(数论+快速幂)

    题目链接: 瞬间移动 Problem Description   有一个无限大的矩形,初始时你在左上角(即第一行第一列),每次你都可以选择一个右下方格子,并瞬移过去(如从下图中的红色格子能直接瞬移到蓝 ...

  3. HDU 5698 瞬间移动

    瞬间移动 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submis ...

  4. hdu5698瞬间移动-(杨辉三角+组合数+乘法逆元)

    瞬间移动 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submis ...

  5. HDU 5698 瞬间移动 数学

    瞬间移动 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5698 Description 有一个无限大的矩形,初始时你在左上角(即第一行第一列),每次 ...

  6. 2016"百度之星" - 初赛(Astar Round2B)1003 瞬间移动 组合数学+逆元

    瞬间移动  Accepts: 1018  Submissions: 3620  Time Limit: 4000/2000 MS (Java/Others)  Memory Limit: 65536/ ...

  7. HDU 5698——瞬间移动——————【逆元求组合数】

    瞬间移动 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submis ...

  8. hdu5698瞬间移动(杨辉三角+快速幂+逆元)

    瞬间移动 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submis ...

  9. 51Nod 1627 瞬间移动 —— 组合数学

    题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1627 1627 瞬间移动  基准时间限制:1 秒 空间限制:1 ...

随机推荐

  1. Codeforces Round #415 (Div. 2) C. Do you want a date?

    C. Do you want a date?   2 seconds 256 megabytes   Leha decided to move to a quiet town Vičkopolis, ...

  2. mianxiangduixiang

    package com.hanqi; public class mianxiang { public static void main(String[]args) { Cat c1 =new Cat( ...

  3. 线程间协作:wait、notify、notifyAll

    线程间协作:wait.notify.notifyAll 在 Java 中,可以通过配合调用 Object 对象的 wait() 方法和 notify()方法或 notifyAll() 方法来实现线程间 ...

  4. js前台实现上传图片的预览

    网上这样的插件一大堆,不过还是谈下js下代码的实现,加深这方面的理解. 当然也没有一种方式就可以完事的情形,主要就两种方面来处理: 1.file API的filereader接口完成(支持的浏览器:I ...

  5. SQL Server ->> 数据一致性检查命令 -- DBCC CHECKDB

    Comming soon!!! 参考文献: CHECKDB From Every Angle: Complete description of all CHECKDB stages

  6. eclipse 实用快捷键(最全)

    注释: (1)Ctrl+Space  说明:内容助理.提供对方法,变量,参数,javadoc等得提示,  应运在多种场合,总之需要提示的时候可先按此快捷键.  注:避免输入法的切换设置与此设置冲突 ( ...

  7. Java SpringMVC学习--基础配置

    快速开始一个基于SpringMVC框架的web项目 开发工具 Eclipse neon.2 运行环境 tomcat8.5 1.在Eclipse中新建一个web项目:File-New-Dynamic W ...

  8. sql with 写法

    with h_asign_id as ( select asign_id from assign_h h left join assignment a on a.id = h.asign_id whe ...

  9. CentOS 6 网络yum源配置

    # CentOS-Base.repo## The mirror system uses the connecting IP address of the client and the# update ...

  10. February 11 2017 Week 6 Saturday

    Love means never having to say you're sorry. 爱就是永远不必说对不起. Yesterday I heard an interesting story fro ...