\(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. Fast-Rcnn学习笔记

    Fast-Rcnn学习笔记 paper code Fast-RCNN总览 step1:图片先放进卷积层 step2:再卷积层的特征图谱上回映射出对应的感兴趣区域 step3:集过一层ROI Pooli ...

  2. 8条github使用小技巧

    1 简介 作为全球最大的开源及私有软件项目托管社区平台,github可以显著地帮助从事编程相关工作的人员提升自己的技术水平,也是费老师我日常最常浏览学习的技术类网站. github为了使得其使用更加便 ...

  3. Navicat可视化MySQL数据库

    Navicat可视化MySQL数据库 Navicat内部封装了所有的操作数据库的命令,用户只需要点击操作即可,无需书写sql语句. navicat能够充当多个数据库的客户端. 具体操作参考百度. py ...

  4. 「Java分享客栈」Nacos配置中心称王称霸,我Apollo一生也不弱于人!

    前言 Apollo又称阿波罗配置中心,在前两年还是挺火的,但阿里SpringCloud套件席卷国内之后,nacos就成为了最被亲睐的分布式配置中心,nacos是配置中心和注册中心二合一的产品,单纯功能 ...

  5. uniapp小程序webSocket封装使用

    目录 1,前言 2,代码实现 3,使用 3.1,初始化 3.2,发送消息 3.3,接收消息 1,前言 最近在做IOT的项目,里面有个小程序要用到webSocket,借这个机会,封装了一个uniapp小 ...

  6. Linux离线包管理器RPM

    Linux离线包管理器RPM RPM 是RedHat Package Manager(RedHat软件包管理工具). 1.rpm常用参数介绍 查看rpm是否安装 rpm -q rpm包名 [root@ ...

  7. Win 系统下使用gnvm操作node版本

    下载 gnvm官方网址 有好几种安装方式,我这里使用的是百度网盘下载. 安装 下载完成将gnvm.exe文件放到node的安装根目录下,如果你不知道安装目录在哪?可以使用命令: where node ...

  8. ABAP CDS - DEFINE VIEW, name_list

    Syntax ... ( name1, name2, ... ) ... Effect Defines the element names of a CDS view in ABAP CDS in a ...

  9. UiPath文本操作Get OCR Text的介绍和使用

    一.Get OCR Text操作的介绍 使用OCR屏幕抓取方法从指示的UI元素或图像中提取字符串及其信息.执行屏幕抓取操作时,还可以自动生成此活动以及容器.默认情况下,使用Google OCR引擎. ...

  10. mysql中in的用法详解

    一.基础用法 mysql中in常用于where表达式中,其作用是查询某个范围内的数据. select * from where field in (value1,value2,value3,-) 当 ...