51nod-1627 瞬间移动(组合数+逆元)
题目描述:
有一个无限大的矩形,初始时你在左上角(即第一行第一列),每次你都可以选择一个右下方格子,并瞬移过去(如从下图中的红色格子能直接瞬移到蓝色格子),求到第n行第m列的格子有几种方案,答案对1000000007取模。

单组测试数据。
两个整数n,m(2<=n,m<=100000)
一个整数表示答案。
4 5
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 瞬间移动(组合数+逆元)的更多相关文章
- 51Nod 1627 瞬间移动 —— 组合数学
题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1627 1627 瞬间移动 基准时间限制:1 秒 空间限制:1 ...
- 51nod 1627 瞬间移动(组合数学)
传送门 解题思路 因为每次横纵坐标至少\(+1\),所以可以枚举走的步数,枚举走的步数\(i\)后剩下的就是把\(n-1\)与\(m-1\)划分成\(i\)个有序正整数相加,所以用隔板法,\(ans= ...
- 51 Nod 1627瞬间移动(插板法!)
1627 瞬间移动 基准时间限制:1 秒 空间限制:131072 KB 分值: 80 难度:5级算法题 收藏 关注 有一个无限大的矩形,初始时你在左上角(即第一行第一列),每次你都可以选择一个右 ...
- 【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} ...
- 51nod 1805 小树 (组合数模板,逆元公式)
题意:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1805 题解: 根据cayley公式,无向图的每一个生成树就对应一个 ...
- hdu5698瞬间移动(组合数,逆元)
瞬间移动 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submis ...
- HDU 5698——瞬间移动——————【逆元求组合数】
瞬间移动 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submis ...
- NOIP2011多项式系数[快速幂|组合数|逆元]
题目描述 给定一个多项式(by+ax)^k,请求出多项式展开后x^n*y^m 项的系数. 输入输出格式 输入格式: 输入文件名为factor.in. 共一行,包含5 个整数,分别为 a ,b ,k , ...
- 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 ...
随机推荐
- html5css练习 旋转
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8&qu ...
- rabbitMq及安装、fanout交换机-分发(发布/订阅)
<dependency> <groupId>com.rabbitmq</groupId> <artifactId& ...
- 团队的Kick off
团队名称:Super power 团队介绍:我们是一个积极向上不乏活力快咯的团队,在一起的任务是happy高效地完成我们的项目. 团队成员自我介绍: 李洪超(项目经理):(男,帅)性格内向,爱好学习, ...
- 解决 IntelliJ IDEA Tomcat 控制台中文输出乱码问题
解决办法 找到安装IDEA的bin目录将idea.exe.vmoptions和idea64.exe.vmoptions两个文件打开分别在文件最末尾添加-Dfile.encoding=UTF-8
- 在java中使用ssm框架的定时的实现
1.首先需要在application.xml里面配置如下的代码: xmlns:task="http://www.springframework.org/schema/task http:// ...
- 2.4JAVA基础复习——JAVA语言的基础组成数组
JAVA语言的基础组成有: 1.关键字:被赋予特殊含义的单词. 2.标识符:用来标识的符号. 3.注释:用来注释说明程序的文字. 4.常量和变量:内存存储区域的表示. 5.运算符:程序中用来运算的符号 ...
- winform Combobox出现System.Data.DataRowView的解决的方法
个人总结: 1.触发了SelectedIndexChanged事件时:comboBox1.DataSource = dt;要放在comboBox1.SelectedIndex = 0;的上面 comb ...
- nginx运用
1.nginx的 命令 start nginx 这样,nginx 服务就启动了.打开任务管理器,查看 nginx.exe 进程,有二个进程会显示,占用系统资源,那是相当的少.然后再打开浏览器,输入 h ...
- 外网登录访问树莓派 Raspberry Pi
外网登录访问树莓派 Raspberry Pi 本地的树莓派 Raspberry Pi,只能在局域网内访问,怎样从公网也能登录访问树莓派 Raspberry Pi? 本文将介绍具体的实现步骤. 1. 准 ...
- CodeForces - 468A
Little X used to play a card game called "24 Game", but recently he has found it too easy. ...