我是靠谱客的博主 幸福小海豚,这篇文章主要介绍AtCoder Regular Contest 058 (组合数学,D - いろはちゃんとマス目 / Iroha and a Grid),现在分享给大家,希望可以做个参考。

题目链接:

https://atcoder.jp/contests/arc058/tasks/arc058_b

题目描述:

Problem Statement

We have a large square grid with HH rows and WW columns. Iroha is now standing

in the top-left cell. She will repeat going right or down to the adjacent cell, until she

reaches the bottom-right cell.

However, she cannot enter the cells in the intersection of the bottom AA rows and

the leftmost BB columns. (That is, there are A×BA×B forbidden cells.) There is no

restriction on entering the other cells.

Find the number of ways she can travel to the bottom-right cell.

Since this number can be extremely large, print the number modulo 109+7109+7.

Constraints

  • 1≦H,W≦100,0001≦H,W≦100,000
  • 1≦A<H1≦A<H
  • 1≦B<W1≦B<W

Input

The input is given from Standard Input in the following format:

复制代码
1
2
HH WW AA BB

Output

Print the number of ways she can travel to the bottom-right cell, modulo 109+7109+7.

Sample Input 1 Copy

Copy

复制代码
1
2
2 3 1 1

Sample Output 1 Copy

Copy

复制代码
1
2
2

We have a 2×32×3 grid, but entering the bottom-left cell is forbidden. The number of

ways to travel is two: "Right, Right, Down" and "Right, Down, Right".

Sample Input 2 Copy

Copy

复制代码
1
2
10 7 3 4

Sample Output 2 Copy

Copy

复制代码
1
2
3570

There are 1212 forbidden cells.

Sample Input 3 Copy

Copy

复制代码
1
2
100000 100000 99999 99999

Sample Output 3 Copy

Copy

复制代码
1
2
1

Sample Input 4 Copy

Copy

复制代码
1
2
100000 100000 44444 55555

Sample Output 4 Copy

Copy

复制代码
1
2
738162020

 

题意:

          给定一个N*M的矩阵,问从左上角到右下角有多少种走法,其中左下角的一块kK*L的矩形不能被经过。

思路:

          首先我们知道,如果没有左下角的限制。那么从左上角到右下角的方案书==C(n+m-2,n-1)。

加上限制以后,想要到达右下角,首先肯定要经过第n-K行,所以我们可以将整条路线分成2段。

另外注意不要直接从中间点到达终点,要注意去重。(这里求组合数不能二维数组打表,可用预处理阶乘,

另外,除法模注意用逆元。)

代码实现:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include<bits/stdc++.h> #define LL long long #define INF 0x3f3f3f3f #define io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0) using namespace std; LL gcd(LL a,LL b) { return b?gcd(b,a%b):a; } bool cmp(int x,int y) { return x>y; } const int N=2e5+100; const LL mod=1e9+7; LL f[N],n,m,A,B; LL powmod(LL x,LL n) { LL s=1; while(n) { if(n&1) s=(s*x)%mod; x=(x*x)%mod; n>>=1; } return s; } LL C(LL n,LL m) { LL a=f[n]; LL b=(f[m]*f[n-m])%mod; return (a*powmod(b,mod-2))%mod;//逆元 } int main() { io; f[0]=1; for(LL i=1; i<N; i++) f[i]=(f[i-1]*i)%mod; while(cin>>n>>m>>A>>B) { LL res=0; for(LL i=B+1; i<=m; i++) { LL tmp=(C(i-1+n-A-1,n-A-1)*C(m-i+A-1,m-i))%mod; res=(res+tmp)%mod; } cout<<res<<endl; } return 0; }

 

The end;

 

最后

以上就是幸福小海豚最近收集整理的关于AtCoder Regular Contest 058 (组合数学,D - いろはちゃんとマス目 / Iroha and a Grid)的全部内容,更多相关AtCoder内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(55)

评论列表共有 0 条评论

立即
投稿
返回
顶部