题意:给出一个棋盘为h*w,现在要从(1,1)到(h,w),其中有n个黑点不能走,问有多少种可能从左上到右下

(1 ≤ h, w ≤ 105, 1 ≤ n ≤ 2000),答案模10^9+7

思路:从(1,1)到(n,m)的方案数是c(n+m-2,n-1)

考虑不能走黑点

设dp[i]为从(1,1)走到(x[i],y[i]),中途没有走过任何一个黑点的方案数

dp[i]=dp[i]-dp[j]*c(x[i]+y[i]-x[j]-y[j],x[i]-x[j]) (x[j]<=x[i]且y[j]<=y[i])

除以阶乘取模用线性求逆元

 const mo=;
var x,y:array[..]of longint;
dp:array[..]of int64;
exf,fac:array[..]of int64;
n,m,k,i,j:longint; procedure swap(var x,y:longint);
var t:longint;
begin
t:=x; x:=y; y:=t;
end; function c(x,y:longint):int64;
begin
// if y= then exit();
exit(fac[x]*exf[y] mod mo*exf[x-y] mod mo);
end; procedure qsort(l,r:longint);
var i,j,mid1,mid2:longint;
begin
i:=l; j:=r; mid1:=x[(l+r)>>]; mid2:=y[(l+r)>>];
repeat
while (mid1>x[i])or(mid1=x[i])and(mid2>y[i]) do inc(i);
while (mid1<x[j])or(mid1=x[j])and(mid2<y[j]) do dec(j);
if i<=j then
begin
swap(x[i],x[j]);
swap(y[i],y[j]);
inc(i); dec(j);
end;
until i>j;
if l<j then qsort(l,j);
if i<r then qsort(i,r);
end; begin
// assign(input,'1.in'); reset(input);
//assign(output,'1.out'); rewrite(output);
readln(n,m,k);
for i:= to k do read(x[i],y[i]);
inc(k); x[k]:=; y[k]:=;
inc(k); x[k]:=n; y[k]:=m;
qsort(,k);
fac[]:=;
for i:= to n+m do fac[i]:=fac[i-]*i mod mo;
exf[]:=; exf[]:=;
for i:= to n+m do exf[i]:=exf[mo mod i]*(mo-mo div i) mod mo;
for i:= to n+m do exf[i]:=exf[i-]*exf[i] mod mo;
dp[]:=;
for i:= to k do
begin
dp[i]:=c(x[i]+y[i]-,x[i]-);
for j:= to i- do
if y[j]<=y[i] then
begin
dp[i]:=dp[i]-dp[j]*c(x[i]-x[j]+y[i]-y[j],x[i]-x[j]);
dp[i]:=(dp[i] mod mo+mo) mod mo;
end;
end;
writeln(dp[k]); //close(input);
//close(output);
end.

【CF559C】 Gerald and Giant Chess(计数,方案数DP,数论)的更多相关文章

  1. CF559C Gerald and Giant Chess

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

  2. $CF559C\ Gerald\ and\ Fiant\ Chess$ 计数类$DP$

    AcWing Description 有个$H$行$W$列的棋盘,里面有$N$个黑色格子,求一个棋子由左上方格子走到右下方格子且不经过黑色格子的方案数. $1<=H,M<=1e5,1< ...

  3. cf559C. Gerald and Giant Chess(容斥原理)

    题意 $h \times w$的网格,有$n$个障碍点, 每次可以向右或向下移动 求从$(1, 1)$到$(h, w)$不经过障碍点的方案数 Sol 容斥原理 从$(1, 1)$到$(h, w)$不经 ...

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

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

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

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

  6. Gerald and Giant Chess

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

  7. E. Gerald and Giant Chess

    E. Gerald and Giant Chess time limit per test 2 seconds memory limit per test 256 megabytes2015-09-0 ...

  8. 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 ...

  9. 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的网格,让你 ...

随机推荐

  1. cron job 里面,如何让脚本半分钟运行一次?

    cron job 里面,如何让脚本半分钟运行一次? cron本身实现不了.但可以借助于sleep命令实现. 解决方法: 两个脚本 一个正常,一个增加sleep 30 crontab设置同时启动 在有的 ...

  2. this经典试题

    <body> <div class="container"> <h3>输出内容</h3> <pre> var name ...

  3. MATLAB编程技巧

    [摘要] MATLAB是一种科学计算语言,和C.Fortran等高级语言相类似,能方便的实现程序控制.以下介绍一点matlab编程的技巧. 嵌套计算 程序执行的速度取决于调用的子程序的个数和算法实现. ...

  4. 【树形dp】bzoj4726: [POI2017]Sabota?

    找点概率期望的题做一做 Description 某个公司有n个人, 上下级关系构成了一个有根树.其中有个人是叛徒(这个人不知道是谁).对于一个人, 如果他 下属(直接或者间接, 不包括他自己)中叛徒占 ...

  5. postman测试传入json

  6. 使用jmeter做简单的压测(检查点、负载设置、聚合报告)

    1.添加断言(检查点) 在需要压测的接口下添加--断言--响应断言,取接口响应中包含有的数据即可 检查点HTTP请求-->断言-->响应断言1.名称.注释2.Apply to//作用于哪里 ...

  7. 使用python3调用MyQR库生成动态二维码(附源代码)

    可生成普通二维码.带图片的艺术二维码(黑白与彩色).动态二维码(黑白与彩色). GitHub:https://github.com/sylnsfar/qrcode 中文版:https://github ...

  8. LeetCode(275)H-Index II

    题目 Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimi ...

  9. LeetCode(151) Reverse Words in a String

    题目 Given an input string, reverse the string word by word. For example, Given s = "the sky is b ...

  10. 使用jquery.layout.js构建页眉/页脚/左侧导航/中间展示内容的网页结构

    背景: 快速将一个页面分成几个部分,在导航和页眉的位置放置公用的元素. 准备: jquery.layout.js 首先,向页面中引入如下js文件和css文件,代码: <link href=&qu ...