题意:给出一个棋盘为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. Servlet的引入(即加入Servlet)

    今天讲的Servlet是根据上一章节<创建一个学生信息表,与页面分离>而结合. 一.看图分析 此模式有问题: 1.jsp需要呼叫javabean StudentService stuSer ...

  2. 功能强大的CURL

      linux下的curl,有着非同一般的魔力,有人称它为下载工具,我更倾向于叫它“文件传输工具”因为它好像无所不能.从常见的 FTP, HTTP, TELNET, 等协议,还支持代理服务器,cook ...

  3. 巧用 Odoo act_window 的 flags实现一些个性化的视图控制

    转自:http://www.khcloud.net:4082/?thread-58.htm 'flags': { 'sidebar': False, //是否显示sidebar区域(主要为action ...

  4. Mysql数据库插入中文出现乱码相关

    查看数据库编码的命令:show variables like "character%"; mysql> show variables like "character ...

  5. 【Git版本控制】git中reset命令的详解

    git reset 命令详解(一) git reset 命令详解(二) reset命令的语法:git reset [选项]  [版本号]  [要回退的目标] 选项:--soft仅将head指针指向历史 ...

  6. 初级练手项目——用Python一步一步实现“智能”贪吃蛇!

    贪吃蛇作为一款经典的小游戏,想必大家一定并不陌生,今天我们就来用Python来设计与实现贪吃蛇游戏,回味一下童年的快乐.快跟着小编来看看吧! ​ 基本环境配置 ●版本:Python3 ●系统:Wind ...

  7. unix cc编译过程

    1.编译并链接一个完全包含与一个源文件的C程序:                cc program.c     这条命令产生一个称为a.out的可执行程序.中间会产生一个名为program.o的目标 ...

  8. Statues CodeForces - 129C(bfs)

    In this task Anna and Maria play a game with a very unpleasant rival. Anna and Maria are in the oppo ...

  9. 求数组中两两相加等于20的组合(Python实现)

    题目 求数组中两两相加等于20的组合. 例:给定一个数组[1, 7, 17, 2, 6, 3, 14],这个数组中满足条件的有两对:17+3=20, 6+14=20. 解析 分为两个步骤: 先采用堆排 ...

  10. Linux学习-透过 systemctl 管理服务

    透过 systemctl 管理单一服务 (service unit) 的启动/开机启动与观察状态 一般来说,服务的启动有两个阶段,一 个是『开机的时候设定要不要启动这个服务』, 以及『你现在要不要启动 ...