\(C_{x+y}^y\)的公式,DP容斥删多余贡献。

#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#define R(a,b,c) for(register int a = (b); (a) <= (c); ++(a))
#define nR(a,b,c) for(register int a = (b); (a) >= (c); --(a))
#define Fill(a,b) memset(a, b, sizeof(a))
#define Swap(a,b) ((a) ^= (b) ^= (a) ^= (b))
#define ll long long
#define u32 unsigned int
#define u64 unsigned long long //#define ON_DEBUGG #ifdef ON_DEBUGG #define D_e_Line printf("\n----------\n")
#define D_e(x) cout << (#x) << " : " << x << endl
#define Pause() system("pause")
#define FileOpen() freopen("in.txt", "r", stdin)
#define FileSave() freopen("out.txt", "w", stdout)
#include <ctime>
#define TIME() fprintf(stderr, "\ntime: %.3fms\n", clock() * 1000.0 / CLOCKS_PER_SEC) #else #define D_e_Line ;
#define D_e(x) ;
#define Pause() ;
#define FileOpen() ;
#define FileSave() ;
#define TIME() ;
//char buf[1 << 21], *p1 = buf, *p2 = buf;
//#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++) #endif using namespace std;
struct ios{
template<typename ATP>inline ios& operator >> (ATP &x){
x = 0; int f = 1; char ch;
for(ch = getchar(); ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = -1;
while(ch >= '0' && ch <= '9') x = x * 10 + (ch ^ '0'), ch = getchar();
x *= f;
return *this;
}
}io; template<typename ATP>inline ATP Max(ATP a, ATP b){
return a > b ? a : b;
}
template<typename ATP>inline ATP Min(ATP a, ATP b){
return a < b ? a : b;
}
template<typename ATP>inline ATP Abs(ATP a){
return a < 0 ? -a : a;
} const int N = 200007;
const int mod = 1000000007; #define int long long
struct nod{
int x, y;
bool operator < (const nod &com) const{
if(x != com.x) return x < com.x;
return y < com.y;
}
}a[N];
int fac[N], inv[N], n, m, K;
inline int Pow(int a, int b){
int s = 1;
while(b){
if(b & 1) s = s * a % mod;
a = a * a % mod, b >>= 1;
}
return s;
}
inline void Init(){
fac[0] = fac[1] = inv[0] = 1;
R(i,2,n + m) fac[i] = fac[i - 1] * i % mod;
R(i,1,n + m) inv[i] = Pow(fac[i], mod - 2);
}
inline int Calc(int x, int y){
if(x < 0 || y < 0) return 0;
return fac[x + y] * inv[x] % mod * inv[y] % mod;
}
int f[N];
#undef int
int main(){
#define int long long
//FileOpen();
//FileSave();
io >> n >> m >> K;
Init();
R(i,1,K){
io >> a[i].x >> a[i].y;
}
sort(a + 1, a + K + 1);
a[K + 1] = (nod){ n, m};
R(i,1,K + 1){
int x = a[i].x - 1, y = a[i].y - 1;
f[i] = Calc(x, y);
R(j,1, i - 1){
int dx = a[i].x - a[j].x, dy = a[i].y - a[j].y;
int del = Calc(dx, dy) * f[j] % mod;
f[i] = (f[i] - del + mod) % mod;
}
}
printf("%lld", f[K + 1]);
return 0;
}

CF 559C - Gerald and Giant Chess (组合计数)的更多相关文章

  1. CodeForces 559C Gerald and Giant Chess

    C. Gerald and Giant Chess time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  2. CF 560e Gerald and Giant Chess

    题意:在h×w的棋盘中从左上角走到右下角,只能向右或向下走,有n个点不可以经过,一共有多少种方案. 解法:dp.先对点按横坐标排序(横坐标相等按纵坐标,也可以反过来)dp[i]表示不经过其他非法点走到 ...

  3. CF-559C Gerald and Giant Chess(计数DP)

    给定一个 \(H*W\)的棋盘,棋盘上只有\(N\) 个格子是黑色的,其他格子都是白色的. 在棋盘左上角有一个卒,每一步可以向右或者向下移动一格,并且不能移动到黑色格子中.求这个卒从左上角移动到右下角 ...

  4. Codeforces 559C Gerald and Giant Chess【组合数学】【DP】

    LINK 题目大意 有一个wxh的网格,上面有n个黑点,问你从(1,1)走到(w,h)不经过任何黑点的方案数 思路 考虑容斥 先把所有黑点按照x值进行排序方便计算 \(dp_{i}\)表示从起点走到第 ...

  5. 【CF559C】 Gerald and Giant Chess(计数,方案数DP,数论)

    题意:给出一个棋盘为h*w,现在要从(1,1)到(h,w),其中有n个黑点不能走,问有多少种可能从左上到右下 (1 ≤ h, w ≤ 105, 1 ≤ n ≤ 2000),答案模10^9+7 思路:从 ...

  6. codeforces(559C)--C. Gerald and Giant Chess(组合数学)

    C. Gerald and Giant Chess time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  7. 【题解】CF559C C. Gerald and Giant Chess(容斥+格路问题)

    [题解]CF559C C. Gerald and Giant Chess(容斥+格路问题) 55336399 Practice: Winlere 559C - 22 GNU C++11 Accepte ...

  8. dp - Codeforces Round #313 (Div. 1) C. Gerald and Giant Chess

    Gerald and Giant Chess Problem's Link: http://codeforces.com/contest/559/problem/C Mean: 一个n*m的网格,让你 ...

  9. Gerald and Giant Chess

    Gerald and Giant Chess time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

随机推荐

  1. 安装Sonarqube到CentOS(YUM)

    SonarQube 是一个用于代码质量管理的开源平台,用于管理源代码的质量. 通过插件形式,可以支持包括 java, C#, C/C++, PL/SQL, Cobol, JavaScrip, Groo ...

  2. 参与 2022 第二季度 Flutter 开发者调查

    2022 Google I/O 大会正式落下帷幕,Flutter 作为 14 个开发者产品和平台中的一款,吸引了来自全球的很多开发者们的关注.随着全国很多地方已经进入夏季,Flutter 今年第二季度 ...

  3. 【原创】史上最简单易懂的kali修改主机名方法

    前言 主机名:在一个局域网中,每台机器都有IP地址,但是IP地址不便于人们记忆.于是采用主机名,即利于主机之间的区分,又方便人们的记忆主机.--和域名差不多. 一,查看当前的主机名 ┌──(root㉿ ...

  4. 计算机网络 - HTTP和HTTPS的区别

    计算机网络 - HTTP和HTTPS的区别 http所有传输的内容都是明文,并且客户端和服务器端都无法验证对方的身份. https具有安全性的ssl加密传输协议,加密采用对称加密. https协议需要 ...

  5. ESXI系列问题整理以及记录——使用SSH为设备打VIB驱动包,同时提供一种对于ESXI不兼容螃蟹网卡(Realtek 瑞昱)的问题解决思路

    对于ESXI不兼容螃蟹网卡的问题,这里建议购买一张博通的低端单口千兆网卡,先使用博通网卡完成系统部署,再按照下文方法添加螃蟹网卡的VIB驱动,最后拆除博通网卡. 螃蟹网卡VIB驱动包下载地址:http ...

  6. 使用Java编写一个日期时间封装类

    package base; import java.util.GregorianCalendar; import java.util.StringTokenizer; import java.util ...

  7. tomcat 的安全配置预防后台被攻击

    安全是系统架构中最重要的关注点之一,通常情况下,所说的安全涵盖网络安全.数据安全.操作系统安全.服务器安全以及应用系统安全等诸多方面. Tomcat 是一个免费的开放源代码 的Web应用服务器,技术先 ...

  8. 我用Python做了一个咖啡馆数据分析

    在做案例前,我还想回答大家一个疑问,就是excel做数据分析可以实现Python一样的效果,那用Python的意义在哪呢? 经过这段时间学习理解,我的回答是: (https://jq.qq.com/? ...

  9. Java 向数组中添加元素

    一般数组是不能添加元素的,因为他们在初始化时就已定好长度了,不能改变长度. 向数组中添加元素思路 第一步:把数组转化为集合 list = Arrays.asList(array); 第二步:向集合中添 ...

  10. [零基础学IoT Pwn] 复现Netgear WNAP320 RCE

    [零基础学IoT Pwn] 复现Netgear WNAP320 RCE 0x00 前言: 这是[零基础学IoT Pwn]的第二篇,上篇我们搭好了仿真环境后,模拟运行了Netgear WNAP320固件 ...