[Luogu 2265]路边的水沟

本文介绍了一个计算特定矩形网格中所有只包含向左和向上移动的水流路径数量的方法。使用了乘法逆元模板来解决大数问题,并通过取模操作确保数值在可处理范围内。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Description

LYQ市有一个巨大的水沟网络,可以近似看成一个n*m的矩形网格,网格的每个格点都安装了闸门,我们将从水沟网络右下角的闸门到左上角的闸门的一条路径称为水流。

现给定水沟网的长和宽,求该水沟网中所有只包含向左和向上移动的水流数量。

Input

输入共1行,包含两个整数n和m。

Output

输出一个数字ans,即水流的数量。由于答案可能很大,请输出答案对1000000007取模的结果。

Sample Input

3 5

Sample Output

56

Hint

对于30%的数据,1 ≤ m,n ≤ 10。

对于50%的数据,1 ≤ m,n ≤ 1,000。

对于80%的数据,1 ≤ m,n ≤ 50,000。

对于100%的数据,1 ≤ m,n ≤ 1,000,000。

题解

乘法逆元模板...

 1 //It is made by Awson on 2017.11.2
 2 #include <map>
 3 #include <set>
 4 #include <cmath>
 5 #include <ctime>
 6 #include <queue>
 7 #include <stack>
 8 #include <cstdio>
 9 #include <string>
10 #include <vector>
11 #include <cstdlib>
12 #include <cstring>
13 #include <iostream>
14 #include <algorithm>
15 #define LL long long
16 #define Max(a, b) ((a) > (b) ? (a) : (b))
17 #define Min(a, b) ((a) < (b) ? (a) : (b))
18 #define Abs(a) ((a) < 0 ? (-(a)) : (a))
19 using namespace std;
20 const int N = 1000000;
21 const int MOD = 1000000007;
22 
23 int n, m;
24 int A[(N<<1)+5];
25 
26 void work() {
27     scanf("%d%d", &n, &m);
28     int ans = 1; A[1] = 1;
29     for (int i = 2; i <= m; i++) A[i] = -(LL)(MOD/i)*A[MOD%i]%MOD;
30     for (int i = n+1; i <= m+n; i++) ans = (LL)ans*i%MOD;
31     for (int i = 2; i <= m; i++) ans = (LL)ans*A[i]%MOD;
32     printf("%d\n", (ans+MOD)%MOD);
33 }
34 int main() {
35     work();
36     return 0;
37 }

 

转载于:https://www.cnblogs.com/NaVi-Awson/p/7772950.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值