题目链接:http://abc042.contest.atcoder.jp/tasks/arc058_b

Time limit : 2sec / Memory limit : 256MB

Score : 400 points

Problem Statement

We have a large square grid with H rows and W 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 A rows and the leftmost B columns. (That is, there are A×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+7.

Constraints

  • 1≦H,W≦100,000
  • 1≦A<H
  • 1≦B<W

Input

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

H W A B

Output

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


Sample Input 1

Copy
2 3 1 1

Sample Output 1

Copy
2

We have a 2×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
10 7 3 4

Sample Output 2

Copy
3570

There are 12 forbidden cells.


Sample Input 3

Copy
100000 100000 99999 99999

Sample Output 3

Copy
1

Sample Input 4

Copy
100000 100000 44444 55555

Sample Output 4

Copy
738162020

题意:n*m矩阵 左下方A*B为禁区,每次可以走下或者左
n,m<=1e5,问从左上到右下不经过禁区时的方案数?

题解:就是找路吧 以为可以动态规划但是数据太大 数组开不了 看了下大佬的 原来可以用组合数

若无禁区,则方案数为C(n+m-2,n-1)
有禁区时 每个合法路径都会到达(n-A,i)i>B 即n-A行的某一列上.
则每个合法路径都可以分成两段,(1,1)->(n-A,i),(n-A,i)->(n,m) (i>B)
注意枚举到(n-A,i)不能向右移动,否则重复枚举.所以路径变为三段.

 #include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#include <queue>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
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+;
const ll mod=1e9+;
ll f[N],n,m,A,B;
ll powmod(ll x,ll n)
{
ll s=;
while(n){
if(n&)
s=(s*x)%mod;
x=(x*x)%mod;
n>>=;
}
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-))%mod;
}
int main()
{
f[]=;
for(ll i=;i<N;i++)
f[i]=(f[i-]*i)%mod;
while(cin>>n>>m>>A>>B){
ll res=;
for(ll i=B+;i<=m;i++){
ll tmp=(C(i-+n-A-,n-A-)*C(m-i+A-,m-i))%mod;
res=(res+tmp)%mod;
}
cout<<res<<endl;
}
return ;
}

いろはちゃんとマス目 / Iroha and a Grid (组合数学)的更多相关文章

  1. AtCoder ABC 042D いろはちゃんとマス目 / Iroha and a Grid

    题目链接:https://abc042.contest.atcoder.jp/tasks/arc058_b 题目大意: 给定一个 H * W 的矩阵,其中左下角 A * B 区域是禁区,要求在不踏入禁 ...

  2. 2018.12.19 atcoder Iroha and a Grid(组合数学)

    传送门 组合数学好题. 给你一个hhh行www列的网格,其中左下角aaa行bbb列不能走,问从左上角走到右下角有多少种走法(每次只能向右或者向下) 我们考虑分步计数. 我们一共能走的区域是总网格区域去 ...

  3. POJ1942——Paths on a Grid(组合数学)

    Paths on a Grid DescriptionImagine you are attending your math lesson at school. Once again, you are ...

  4. poj 1924 Paths on a Grid(组合数学)

    题目:http://poj.org/problem?id=1942 题意:给定一个矩形网格的长m和高n,其中m和n都是unsigned int32类型,一格代表一个单位,就是一步,求从左下角到右上角有 ...

  5. Iroha and a Grid AtCoder - 1974(思维水题)

    就是一个组合数水题 偷个图 去掉阴影部分  把整个图看成上下两个矩形 对于上面的矩形求出起点到每个绿点的方案 对于下面的矩形 求出每个绿点到终点的方案 上下两个绿点的方案相乘后相加 就是了 想想为什么 ...

  6. AtCoder-arc058(题解)

    A - こだわり者いろはちゃん / Iroha's Obsession(暴力) 题目链接 题目大意: 给你 \(k\) 个个位数字和一个数字 \(n\) ,要求找到一个大于等于n的数字,使得不出现 \ ...

  7. csp退役前的做题计划1(真)

    csp退役前的做题计划1(真) 因为我太菜了,所以在第一次月考就会退役,还是记录一下每天做了什么题目吧. 任务计划 [ ] Z算法(Z Algorithm) 9.28 [x] ARC061C たくさん ...

  8. 【AtCoder】ARC058

    ARC058 C - こだわり者いろはちゃん / Iroha's Obsession 暴力一个个枚举是最简单的方式 #include <bits/stdc++.h> #define fi ...

  9. AtCoder Regular Contest 058

    这个应该是第一场有英文的atcoder吧??不过题解却没有英文的... 从前往后慢慢做... C こだわり者いろはちゃん / Iroha's Obsession 数据范围这么小,直接暴力 #inclu ...

随机推荐

  1. C# install-package:"xx"已拥有为“xxx”定义的依赖项

    可能 nuget自身的版本落后于适配程序包的版本 Visual Studio 2013 更新 NuGet 包管理器 Ø  前言 使用 Visual Studio 中的 NuGet 包管理器下载程序时, ...

  2. python文件的md5加密方法

    本文实例讲述了python文件的md5加密方法.分享给大家供大家参考,具体如下: 一.简单模式: from hashlib import md5 def md5_file(name): m = md5 ...

  3. 【SVM】周志华

    一.书籍(121-139)

  4. Oracle(2)之多表查询&子查询&集合运算

    多表查询 笛卡尔积 同时查询多张表时,每张表的每条数据都要和其它表的每条数据做组合.如下栗子,我们发现产生的总记录数是 56 条,还发现 emp 表是 14 条,dept 表是 4 条,56 条正是 ...

  5. 网络编程——socket编程

    一.客户端/服务端架构 1.硬件C/S架构(打印机) 2.软件C/S架构 互联网企业处处是C/S架构 C/S架构与socket的关系:学习socket就是为了完成C/S架构的开发 二.OSI七层 一个 ...

  6. 一文看懂POS收单中"MCC"是什么意思?

    MCC的前世今生! 是否经常听人提起过“MCC”?听起来如此高大上的词,背后有着怎样的知识内涵呢?您知道吗?今天,我们就一起来了解了解“MCC”的前世今生,让它也“接接地气”吧!商户类别码(简称MCC ...

  7. (转)Java静态内部类的实例化问题

    最近遇到的一个问题,记录一下. 静态内部类可以被实例化! 1.首先在外部类中的static方法中不能使用普通内部类,因为内部类必须要与外部类建立关联才能使用,可以说是同生共死. 2.我在编码过程中,需 ...

  8. 9个Linux系统常用监控命令

    我们的系统一旦上线跑起来我们自然希望它一直相安无事,不要宕机,不要无响应,不要慢腾腾的.但是这不是打开机器电源然后放任不管就可以得到的.所以我们要监视系统的运行状况,发现问题及时处理. 对于系统和网络 ...

  9. MVC 中url-pattern配置为"/"和"/*"的区别

    首先大家都知道"/*"可以匹配所有url,包括带扩展名的,一般只用在过滤器上. 而"/"很多人理解成不能拦截带扩展名的,这种理解是错误的!它其实也能拦截“.js ...

  10. RCNN系列算法的发展

    一. RCNN系列的发展 1.1  R-CNN 根据以往进行目标检测的方法,在深度学习应用于目标检测时,同样首先尝试使用滑动窗口的想法,先对图片进行选取2000个候选区域,分别对这些区域进行提取特征以 ...