Codeforces Round #313 (Div. 2) E. Gerald and Giant Chess (Lucas + dp)
题目链接:http://codeforces.com/contest/560/problem/E
给你一个n*m的网格,有k个坏点,问你从(1,1)到(n,m)不经过坏点有多少条路径。
先把这些坏点排序一下。
dp[i]表示从(1,1)到第i个坏点且不经过其他坏点的路径数目。
dp[i] = Lucas(x[i], y[i]) - sum(dp[j]*Lucas(x[i]-x[j], y[i]-x[j])) , x[j] <= x[i] && y[j] <= y[i] //到i点所有的路径数目 - 经过其他点的路径数目
//#pragma comment(linker, "/STACK:102400000, 102400000")
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
typedef __int64 LL;
typedef pair <int, int> P;
const int N = 2e3 + ;
struct Node {
LL x, y;
bool operator <(const Node &cmp) const {
return x == cmp.x ? y < cmp.y : x < cmp.x;
}
}node[N];
LL mod = 1e9 + ;
LL dp[N]; //经过i点不经过其他点的case数
LL f[]; //阶乘 LL Pow(LL a , LL n , LL mod) {
LL res = ;
while(n) {
if(n & )
res = res * a % mod;
a = a * a % mod;
n >>= ;
}
return res;
} LL Comb(LL a , LL b , LL mod) {
if(a < b) {
return ;
}
if(a == b) {
return ;
}
return f[a] * Pow(f[a - b] * f[b] % mod, mod - , mod) % mod;
} LL Lucas(LL n , LL m , LL mod) {
LL ans = ;
while(m && n && ans) {
ans = (ans * Comb(n % mod , m % mod , mod)) % mod;
n /= mod;
m /= mod;
}
return ans;
} int main()
{
f[] = ;
for(LL i = ; i <= ; ++i) {
f[i] = f[i - ] * i % mod;
}
LL row, col, sum;
int n;
scanf("%lld %lld %d", &row, &col, &n);
for(int i = ; i <= n; ++i) {
scanf("%lld %lld", &node[i].x, &node[i].y);
node[i].x--, node[i].y--;
}
sort(node + , node + n + );
for(int i = ; i <= n; ++i) {
sum = ;
for(int j = ; j < i; ++j) {
if(node[i].x >= node[j].x && node[i].y >= node[j].y) {
sum = (dp[j]*Lucas(node[i].x + node[i].y - node[j].x - node[j].y, node[i].x - node[j].x, mod) % mod + sum) % mod;
}
}
dp[i] = ((Lucas(node[i].x + node[i].y, node[i].x, mod) - sum) % mod + mod) % mod;
}
sum = ;
for(int i = ; i <= n; ++i) {
sum = (dp[i]*Lucas(row + col - - node[i].x - node[i].y, row - - node[i].x, mod) % mod + sum) % mod;
}
printf("%lld\n", ((Lucas(row + col - , col - , mod) - sum) % mod + mod) % mod);
return ;
}
Codeforces Round #313 (Div. 2) E. Gerald and Giant Chess (Lucas + dp)的更多相关文章
- 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的网格,让你 ...
- Codeforces Round #313 (Div. 1) C. Gerald and Giant Chess DP
C. Gerald and Giant Chess Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest ...
- Codeforces Round #313 (Div. 1) C. Gerald and Giant Chess
这场CF又掉分了... 这题题意大概就给一个h*w的棋盘,中间有一些黑格子不能走,问只能向右或者向下走的情况下,从左上到右下有多少种方案. 开个sum数组,sum[i]表示走到第i个黑点但是不经过其他 ...
- Codeforces Round #313 (Div. 1) A. Gerald's Hexagon
Gerald's Hexagon Problem's Link: http://codeforces.com/contest/559/problem/A Mean: 按顺时针顺序给出一个六边形的各边长 ...
- Codeforces Round #313 (Div. 2) C. Gerald's Hexagon 数学
C. Gerald's Hexagon Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/559/pr ...
- Codeforces Round #313 (Div. 1) A. Gerald's Hexagon 数学题
A. Gerald's Hexagon Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/559/p ...
- Codeforces Round #313 (Div. 2) B. Gerald is into Art 水题
B. Gerald is into Art Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/560 ...
- 【打CF,学算法——三星级】Codeforces Round #313 (Div. 2) C. Gerald's Hexagon
[CF简单介绍] 提交链接:http://codeforces.com/contest/560/problem/C 题面: C. Gerald's Hexagon time limit per tes ...
- Codeforces Round #313 (Div. 2) C. Gerald's Hexagon(补大三角形)
C. Gerald's Hexagon time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
随机推荐
- [xUnix 开发环境--01] MAMP mac os 10.10 配置经历、要点——01. phpmyadmin连不上
Mac OS 10.10已经自带了apache2和php(php的路径我至今还没不知道,太懒没去找) 用brew安装mysql, 在官网上下载了phpmyadmin,按官方方式配置完后,登录不上,也不 ...
- matlab中矩阵和向量的创建
1.向量的创建 1)直接输入: 行向量:a=[1,2,3,4,5] 列向量:a=[1;2;3;4;5] 2)用“:”生成向量 a=J:K 生成的行向量是a=[J,J+1,…,K] a=J:D:K 生成 ...
- 【英文】Bingo口语笔记(18) - Cover系列
cover charge 服务费 cover version 翻唱版本 cover the news 头条新闻
- Dataguard后台进程解析
Log Transport Service 主节点上,日志传输服务主要使用如下几个进程: 1.LGWR LGWR搜集事务日志,并且更新联机日志.在同步模式下,LGWR直接将redo信息直接 ...
- Android Retrofit实现原理分析
retrofit有几个关键的地方. 1.用户自定义的接口和接口方法.(由动态代理创建对象.) 2.converter转换器.(把response转换为一个具体的对象) 3.注解的使用. 让我们跟随Ap ...
- MySQL与Oracle 差异比较之六触发器
触发器 编号 类别 ORACLE MYSQL 注释 1 创建触发器语句不同 create or replace trigger TG_ES_FAC_UNIT before insert or upd ...
- CSS打造三级下拉菜单
<html><head><meta http-equiv="Content-Type" content="text/html; charse ...
- RIA+REST架构实现完美WEB开发
记得第一次看到REST的身影,是在InfoQ上的一篇介绍,随后又翻阅了后面的参考文章和Developerwork上一些资料,甚至随手翻了翻Roy博士的论文.所幸,在不少人还在体会REST到底是何方神圣 ...
- [整] Android Fragment 生命周期图
1. onAttach ------called once the fragment is associated with its activity 2. onCreate-------called ...
- js正则表达式中=s.g表示什么意思
//g是全局匹配//中间的内容表示:匹配以=开关,后面是0或多个空格,然后是双引号括起来的任意字符,比如:= "any symble" 匹配 = " asfjaskldf ...