题目描述:

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

Input
单组测试数据。
两个整数n,m(2<=n,m<=100000)
Output
一个整数表示答案。
Input示例
4 5
Output示例
10

题目分析:定义f(n,m)为从左上角走到(n,m)的所有方案数。显然有f(n,m)=∑ ∑ f(i,j),其中1≤i<n、j≤1<m。这是组合数。

代码如下:
#include <stdio.h>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <math.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm> //#define _COMPLIE
#ifdef _COMPLIE
#include "51nod_1627.h"
#endif // _COMPLIE using namespace std; typedef long long LL;
const int mod=1000000007;
const int N=200000; class nod_1627
{
private:
int n,m;
LL c[N+5];
void getC(int x);
LL myPow(LL a,int x);
public:
void input();
void process();
void output();
}; void nod_1627::input()
{
scanf("%d%d",&n,&m);
} LL nod_1627::myPow(LL a,int x)
{
LL res=1;
while(x){
if(x&1)
res=(res*a)%mod;
a=(a*a)%mod;
x>>=1;
}
return res; } void nod_1627::getC(int x)
{
c[0]=c[x]=1;
c[1]=c[x-1]=x;
for(int i=2;i<=x/2;++i){
c[x-i]=c[i]=(((c[i-1]*(LL)(x-i+1))%mod)*myPow(i,mod-2))%mod;
}
} void nod_1627::process()
{
--n,--m;
getC(n+m-2);
} void nod_1627::output()
{
printf("%lld\n",c[m-1]);
} int main()
{
//freopen("in.txt","r",stdin);
nod_1627 problem;
problem.input();
problem.process();
problem.output();
return 0;
}

51nod-1627 瞬间移动(组合数+逆元)的更多相关文章

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

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

  2. 51nod 1627 瞬间移动(组合数学)

    传送门 解题思路 因为每次横纵坐标至少\(+1\),所以可以枚举走的步数,枚举走的步数\(i\)后剩下的就是把\(n-1\)与\(m-1\)划分成\(i\)个有序正整数相加,所以用隔板法,\(ans= ...

  3. 51 Nod 1627瞬间移动(插板法!)

    1627 瞬间移动  基准时间限制:1 秒 空间限制:131072 KB 分值: 80 难度:5级算法题  收藏  关注 有一个无限大的矩形,初始时你在左上角(即第一行第一列),每次你都可以选择一个右 ...

  4. 【HDU 5698】瞬间移动(组合数,逆元)

    x和y分开考虑,在(1,1)到(n,m)之间可以选择走i步.就需要选i步对应的行C(n-2,i)及i步对应的列C(m-2,i).相乘起来. 假设$m\leq n$$$\sum_{i=1}^{m-2} ...

  5. 51nod 1805 小树 (组合数模板,逆元公式)

    题意:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1805 题解: 根据cayley公式,无向图的每一个生成树就对应一个 ...

  6. hdu5698瞬间移动(组合数,逆元)

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

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

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

  8. NOIP2011多项式系数[快速幂|组合数|逆元]

    题目描述 给定一个多项式(by+ax)^k,请求出多项式展开后x^n*y^m 项的系数. 输入输出格式 输入格式: 输入文件名为factor.in. 共一行,包含5 个整数,分别为 a ,b ,k , ...

  9. 2016 ACM/ICPC Asia Regional Shenyang Online 1003/HDU 5894 数学/组合数/逆元

    hannnnah_j’s Biological Test Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K ...

随机推荐

  1. SpringCloud入门之应用程序上下文服务(Spring Cloud Context)详解

    构建分布式系统非常复杂且容易出错.Spring Cloud为最常见的分布式系统模式提供了简单易用的编程模型,帮助开发人员构建弹性,可靠和协调的应用程序.Spring Cloud构建于Spring Bo ...

  2. Lua table遍历

    工作中,栽了一个“坑”,特此备录. [1]遍历table1,每次结果可能都不同 -- 获取value ", addr="xian"} for k, v in pairs( ...

  3. STD函数的内部计算公式

    各股票软件的标准差函数STD是不同的,而布林线的上下轨是以STD为基础计算出来的,所以使用布林线应小心.以2008/3/28的上证综指为例,利用如下代码:"收盘价3日STD:STD(CLOS ...

  4. vue使用v-for时vscode报错 Elements in iteration expect to have 'v-bind:key' directives

    vue使用v-for时vscode报错 Elements in iteration expect to have 'v-bind:key' directives Vue 2.2.0+的版本里,当在组件 ...

  5. 2.获取指定目录及子目录下所有txt文件的个数,并将这些txt文件复制到F盘下任意目录

    package cn.it.text; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import ...

  6. jquery serializeArray()、serialize()增加数据

    转自:http://blog.csdn.net/csdnzhangtao5/article/details/52981541 serialize().serializeArray()方法都是jquer ...

  7. 项目添加大量js文件时关闭Eclipse校验机制

    1,如:当添加Ext JS的examples文件夹时

  8. lnmp mysql远程访问设置

    一:iptables 设置开放3306访问 iptables -L -n --line-numbers 1,删除DROP 3306 iptables -D INPUT 5[序列号] 2,添加 ACCE ...

  9. java0422 wen 集合框架

  10. bzoj4665 小w的喜糖(dp+容斥)

    4665: 小w的喜糖 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 222  Solved: 130[Submit][Status][Discuss ...