CF 559C - Gerald and Giant Chess (组合计数)
\(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 (组合计数)的更多相关文章
- 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 ...
- CF 560e Gerald and Giant Chess
题意:在h×w的棋盘中从左上角走到右下角,只能向右或向下走,有n个点不可以经过,一共有多少种方案. 解法:dp.先对点按横坐标排序(横坐标相等按纵坐标,也可以反过来)dp[i]表示不经过其他非法点走到 ...
- CF-559C Gerald and Giant Chess(计数DP)
给定一个 \(H*W\)的棋盘,棋盘上只有\(N\) 个格子是黑色的,其他格子都是白色的. 在棋盘左上角有一个卒,每一步可以向右或者向下移动一格,并且不能移动到黑色格子中.求这个卒从左上角移动到右下角 ...
- Codeforces 559C Gerald and Giant Chess【组合数学】【DP】
LINK 题目大意 有一个wxh的网格,上面有n个黑点,问你从(1,1)走到(w,h)不经过任何黑点的方案数 思路 考虑容斥 先把所有黑点按照x值进行排序方便计算 \(dp_{i}\)表示从起点走到第 ...
- 【CF559C】 Gerald and Giant Chess(计数,方案数DP,数论)
题意:给出一个棋盘为h*w,现在要从(1,1)到(h,w),其中有n个黑点不能走,问有多少种可能从左上到右下 (1 ≤ h, w ≤ 105, 1 ≤ n ≤ 2000),答案模10^9+7 思路:从 ...
- 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 ...
- 【题解】CF559C C. Gerald and Giant Chess(容斥+格路问题)
[题解]CF559C C. Gerald and Giant Chess(容斥+格路问题) 55336399 Practice: Winlere 559C - 22 GNU C++11 Accepte ...
- 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的网格,让你 ...
- Gerald and Giant Chess
Gerald and Giant Chess time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
随机推荐
- Docker搭建大数据集群 Hadoop Spark HBase Hive Zookeeper Scala
Docker搭建大数据集群 给出一个完全分布式hadoop+spark集群搭建完整文档,从环境准备(包括机器名,ip映射步骤,ssh免密,Java等)开始,包括zookeeper,hadoop,hiv ...
- Windows环境下安装RabbitMQ
本地安装RabbitMQ安装注意事项: Erlang与RabbitMQ,安装路径都应不含空格符. Erlang使用了环境变量HOMEDRIVE与HOMEPATH来访问配置文件.erlang.cooki ...
- 重载overload 、重写override
观点:重载和重写完全没有关系要联系到一起,唯一的联系就是他们都带有个'重'字,所以鄙人也随大流把他们放在了一起 注意:下面可复制的代码是正确的,错误的只会上传图片,不上传可复制的代码 重载 1.在同一 ...
- Linux系统安装ActiveMQ
下载安装包 https://activemq.apache.org/components/classic/download/ 上传至服务器并解压 [root@localhost activemq]# ...
- 十二张图:从0开始理解对称/非对称加密、CA认证、以及K8S各组件颁发证书原由
目录 一.对称加密 二.对称加密-不安全 三.非对称加密 四.非对称加密-不安全 五.对称加密和非对称加密结合 六.对称加密和非对称加密结合-不安全 七.Https的做法-引入CA机构 八.乘胜追击理 ...
- WinForms获得已打开窗体的引用
更新记录 本文迁移自Panda666原博客,原发布时间:2021年7月6日. 对于已经打开的窗口,可以通过Application.OpenForms属性进行获得.该属性是一个FormCollectio ...
- 第1期 考研中有关函数的一些基本性质《zobol考研微积分学习笔记》
在入门考研微积分中,我们先复习一部分中学学的初等数学的内容.函数是非常有用的数学工具. 1.函数的性质理解: 首先考研数学中的所有函数都是初等函数.而函数的三个关键就是定义域.值域.对应关系f. 其中 ...
- web自动化之元素定位篇
一.web自动化元素定位的方式有8种.------腾讯课堂 1.1 id定位: 1.2 class定位: 1.3 classname定位 1.4 tag_name 1.5
- 两分钟解决Python读取matlab的.mat数据
Matlab是学术界非常受欢迎的科学计算平台,matlab提供强大的数据计算以及仿真功能.在Matlab中数据集通常保存为.mat格式.那么如果我们想要在Python中加载.mat数据应该怎么办呢?所 ...
- CANN算子:利用迭代器高效实现Tensor数据切割分块处理
摘要:本文以Diagonal算子为例,介绍并详细讲解如何利用迭代器对n维Tensor进行基于位置坐标的大批量数据读取工作. 本文分享自华为云社区<CANN算子:利用迭代器高效实现Tensor数据 ...