いろはちゃんとマス目 / Iroha and a Grid (组合数学)
题目链接: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
2 3 1 1
Sample Output 1
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
10 7 3 4
Sample Output 2
3570
There are 12 forbidden cells.
Sample Input 3
100000 100000 99999 99999
Sample Output 3
1
Sample Input 4
100000 100000 44444 55555
Sample Output 4
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 (组合数学)的更多相关文章
- AtCoder ABC 042D いろはちゃんとマス目 / Iroha and a Grid
题目链接:https://abc042.contest.atcoder.jp/tasks/arc058_b 题目大意: 给定一个 H * W 的矩阵,其中左下角 A * B 区域是禁区,要求在不踏入禁 ...
- 2018.12.19 atcoder Iroha and a Grid(组合数学)
传送门 组合数学好题. 给你一个hhh行www列的网格,其中左下角aaa行bbb列不能走,问从左上角走到右下角有多少种走法(每次只能向右或者向下) 我们考虑分步计数. 我们一共能走的区域是总网格区域去 ...
- POJ1942——Paths on a Grid(组合数学)
Paths on a Grid DescriptionImagine you are attending your math lesson at school. Once again, you are ...
- poj 1924 Paths on a Grid(组合数学)
题目:http://poj.org/problem?id=1942 题意:给定一个矩形网格的长m和高n,其中m和n都是unsigned int32类型,一格代表一个单位,就是一步,求从左下角到右上角有 ...
- Iroha and a Grid AtCoder - 1974(思维水题)
就是一个组合数水题 偷个图 去掉阴影部分 把整个图看成上下两个矩形 对于上面的矩形求出起点到每个绿点的方案 对于下面的矩形 求出每个绿点到终点的方案 上下两个绿点的方案相乘后相加 就是了 想想为什么 ...
- AtCoder-arc058(题解)
A - こだわり者いろはちゃん / Iroha's Obsession(暴力) 题目链接 题目大意: 给你 \(k\) 个个位数字和一个数字 \(n\) ,要求找到一个大于等于n的数字,使得不出现 \ ...
- csp退役前的做题计划1(真)
csp退役前的做题计划1(真) 因为我太菜了,所以在第一次月考就会退役,还是记录一下每天做了什么题目吧. 任务计划 [ ] Z算法(Z Algorithm) 9.28 [x] ARC061C たくさん ...
- 【AtCoder】ARC058
ARC058 C - こだわり者いろはちゃん / Iroha's Obsession 暴力一个个枚举是最简单的方式 #include <bits/stdc++.h> #define fi ...
- AtCoder Regular Contest 058
这个应该是第一场有英文的atcoder吧??不过题解却没有英文的... 从前往后慢慢做... C こだわり者いろはちゃん / Iroha's Obsession 数据范围这么小,直接暴力 #inclu ...
随机推荐
- MongoDB的客户端管理工具--nosqlbooster 查询工具使用
连接我的MongoDB 看到这样 打开db1数据库里面user集合,看到user集合里面的数据,他会自带查询语句 看这里以tree方式显示 可以以table方式显示 还可以json方式显示 按照自己的 ...
- 前端 HTML body标签相关内容 常用标签 列表标签 ul,ol,li
列表标签 ul,ol,li ul.ol.li标签 都属于块级标签,独占一行 网站页面上一些列表相关的内容比如说物品列表.人名列表等等都可以使用列表标签来展示.通常后面跟<li>标签一起用, ...
- 小程序支持连Wi-Fi,代码包到4M
小程序又开发新能力了:1 更多硬件连接功能等着你.在商场等场所,用户以往要用微信连Wi-Fi,要扫二维码并关注公众号,点击菜单里的“连Wi-Fi”才能使用上网络.连个Wi-Fi何必让用户经过两道坎? ...
- Vagrant测试
载新的BOX实现虚拟机恢复.效果如下:(可用linux命令操作,但是很多时候我们还是需要图形化界面,不然不利于开发代码编写) 参考PDF中的记录网址http://www.vagrantbox.es/ ...
- Nginx的基础配置管理
Nginx的基本功能 1.静态资源的web服务器 2.http协议反向代理服务器 3.tcp/udp协议的请求转发 安装nginx yum install epel-release yum insta ...
- 014-通过JDB调试,通过HSDB来查看HotSpot VM的运行时数据
一.JDB调试 在预发环境下进行debug时,时常因为工具和环境的限制,导致debug体验非常差,那么有什么方法能够简化我们进行debug的体验吗?JDB就是一种. JDB ...
- [硬件]Robot运动控制
思考问题:机器人运动控制如何与图形界面交互? 不得不说,先锋机器人的软件做的真不怎么样.图形界面交互用户体验很差. 现在我遇到一个很现实的问题:SLAM需要采集激光数据和机器人的位姿,同时我还要再这个 ...
- sap 提供服务
1: https://blog.csdn.net/stone0823/article/details/81661261?utm_source=blogxgwz1 https://blog.csdn.n ...
- [py][mx]django处理登录逻辑
浏览器同源策略(same-origin policy) csrf攻击防御核心点总结 django的cookie和session操作-7天免登录 flask操作cookie&django的see ...
- IOP知识点(1)
1 实例明细url显示 2 增加了logo图片可以编辑 1 实例明细url显示 是在iop中写死的配置 2 增加了logo图片可以编辑 仿照 admin里 服务工厂-服务定义中的内容 (1) ...