\(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;
}

最新文章

  1. linux下的gcc编译器
  2. mybatis 传递参数的方法总结
  3. Spring+Maven+Dubbo+MyBatis+Linner+Handlebars—Web开发环境搭建
  4. 目前国内外主流的linux发行版本
  5. wordpress 404 error on all pages!
  6. bzoj3431 [Usaco2014 Jan]Bessie Slows Down
  7. HDOJ-1012 u Calculate e(水)
  8. LaTeX新人教程,30分钟从全然陌生到基本入门
  9. 复习面向对象的OOA、OOD、OOP
  10. [bzoj1700]: [Usaco2007 Jan]Problem Solving 解题
  11. NOIP2017+停课总结
  12. Centos 6 搭建安装 Gitlab
  13. node_acl 路径通配
  14. Jar包的手动导入
  15. index.php入口文件至根目录
  16. flask框架----信号
  17. day85
  18. Java8学习笔记(七)--Collectors
  19. group by 错误
  20. Hive 优化汇总

热门文章

  1. consul系列文章02---替换掉.netcore的配置文件
  2. 两个月吃透阿里P9推荐260页SpringBoot2企业应用实战pdf入职定P6+
  3. CA证书介绍与格式转换
  4. HashMap 中的 hash 函数
  5. 软件性能测试分析与调优实践之路-JMeter对RPC服务的性能压测分析与调优-手稿节选
  6. Java - ConcurrentHashMap的原理
  7. 文件输入输出处理-File
  8. Leetcode 1051. 高度检查器
  9. 利用kubernetes资源锁完成自己的HA应用
  10. python写个前端,这不是轻轻松松~