题意:给出一个棋盘为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. 【最大权闭合子图 最小割】bzoj1497: [NOI2006]最大获利

    最大权闭合子图的模型:今天才发现dinic板子是一直挂的…… Description 新的技术正冲击着手机通讯市场,对于各大运营商来说,这既是机遇,更是挑战.THU集团旗下的CS&T通讯公司在 ...

  2. tempfs详解

    致因 在平常工作中,我们经常需要查看Linux服务器磁盘挂载使用情况,可以使用df命令,不知大家注意到没有,我们使用此命令除了会查看到系统盘以及数据盘挂载情况,还会看到一个tmpfs也在挂载. [ro ...

  3. Python——format汇总

    一.str.format 按照指定格式格式化字符串,然后返回格式化的字符串,源字符串不变. 以下是Python2.7环境. 1.1.按照位置替换 参考下面例子: >>> s = '{ ...

  4. 【 android】When an app is installed on the external storage

    When an app is installed on the external storage: The .apk file is saved to the external storage, bu ...

  5. python爬虫基础13-selenium大全7/8-异常

    Selenium笔记(7)异常 本文集链接:https://www.jianshu.com/nb/25338984 完整文档 Exceptions that may happen in all the ...

  6. LeetCode(258) Add Digits

    题目 Given a non-negative integer num, repeatedly add all its digits until the result has only one dig ...

  7. python基础学习笔记——字典

    字典(Dictionary) 字典是另一种可变容器模型,且可存储任意类型对象. 字典的每个键值 key=>value 对用冒号 : 分割,每个键值对之间用逗号 , 分割,整个字典包括在花括号 { ...

  8. day37-- &MySQL step1

    m1.客户端与数据库服务器端是通过socket来交互数据,对数据库的理解:数据库就是一个文件夹,表就类比文件.m2.常用语句#查看数据库show databases:#创建数据库create data ...

  9. 令人惊叹的sublime text 3 插件

    1.Chinese​Localization------语言汉化.(新手必备) 2.SublimeTmpl------打开生成模板.(新手必备) 3.SublimeCodeIntel------代码自 ...

  10. [Cake] 2. dotnet 全局工具 cake

    在上篇博客[Cake] 1. CI中的Cake中介绍了如何在CI中利用Cake来保持与CI/CD环境的解耦. 1. 简化cake的安装 当时dotnet 2.1还未正式发布,dotnet 还没有工具的 ...