【题解】CF559C C. Gerald and Giant Chess(容斥+格路问题)
【题解】CF559C C. Gerald and Giant Chess(容斥+格路问题)
| 55336399 | Practice: Winlere | 559C - 22 | GNU C++11 | Accepted | 186 ms | 1608 KB | 2019-06-09 17:03:21 | 2019-06-09 17:03:21 |
|---|---|---|---|---|---|---|---|---|
一道小水题(为什么2400??我为什么之前被一道2200锤QAQ)
有个很显然的公式,在组合数学那本书上面也有。
从坐标\((0,0)\)到坐标\((x,y)\)总共有\({x+y}\choose x\)种不回头走的办法。
证明显然,考虑从\((0,0)\)到\((x,y)\)一定要走\(x+y\)步,从中随意抽出\(x\)步向\(x\)正半轴走就构成了我们的路径条数。记为\(G(x,y)\)吧
\(dp(i,j)\)表示从原点到此有多少条合法的路径。转移从所有可以阻挡住他的点来。
我会出一篇总结组合数学那本书上面的结论的博客,密码:orzyyb。
//@winlere
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define x first
#define y second
using namespace std; typedef long long ll;
inline int qr(){
register int ret=0,f=0;
register char c=getchar();
while(c<48||c>57)f|=c==45,c=getchar();
while(c>=48&&c<=57) ret=ret*10+c-48,c=getchar();
return f?-ret:ret;
}
const int maxn=2e5+5;
const int mod=1e9+7;
int fac[maxn],inv[maxn],dp[2001],n;
pair < int , int > data[2001];
inline int ksm(int base,const int&p){register int ret=1;
for(register int t=p;t;t>>=1,base=1ll*base*base%mod)if(t&1) ret=1ll*ret*base%mod;
return ret;
}
inline int c(const int&n,const int&m){return n<m?0:1ll*fac[n]*inv[m]%mod*1ll*inv[n-m]%mod;}
inline int grid(const int&x,const int&y){return c(x+y,x);}
int main(){
fac[0]=inv[0]=1;
for(register int t=1;t<maxn;++t) fac[t]=1ll*fac[t-1]*t%mod,inv[t]=ksm(fac[t],mod-2);
data[0].x=qr();data[0].y=qr();n=qr();
for(register int t=1;t<=n;++t) data[t].x=qr(),data[t].y=qr();
sort(data,data+n+1);
for(register int t=0;t<=n+1;++t){
dp[t]=grid(data[t].x-1,data[t].y-1);
for(register int i=0;i<t;++i){
dp[t]=(dp[t]-1ll*dp[i]*grid(data[t].x-data[i].x,data[t].y-data[i].y)%mod)%mod;
if(dp[t]<0) dp[t]+=mod;
}
}
cout<<dp[n]<<endl;
return 0;
}
【题解】CF559C C. Gerald and Giant Chess(容斥+格路问题)的更多相关文章
- 【CF559C】 Gerald and Giant Chess(计数,方案数DP,数论)
题意:给出一个棋盘为h*w,现在要从(1,1)到(h,w),其中有n个黑点不能走,问有多少种可能从左上到右下 (1 ≤ h, w ≤ 105, 1 ≤ n ≤ 2000),答案模10^9+7 思路:从 ...
- CF559C Gerald and Giant Chess
题意 C. Gerald and Giant Chess time limit per test 2 seconds memory limit per test 256 megabytes input ...
- 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 ...
- 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 559C Gerald and Giant Chess
C. Gerald and Giant Chess time limit per test 2 seconds memory limit per test 256 megabytes input st ...
- Gerald and Giant Chess
Gerald and Giant Chess time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- E. Gerald and Giant Chess
E. Gerald and Giant Chess time limit per test 2 seconds memory limit per test 256 megabytes2015-09-0 ...
- codeforces(559C)--C. Gerald and Giant Chess(组合数学)
C. Gerald and Giant Chess time limit per test 2 seconds memory limit per test 256 megabytes input st ...
- 2018.11.07 codeforces559C. Gerald and Giant Chess(dp+组合数学)
传送门 令f[i]f[i]f[i]表示对于第iii个棋子,从(1,1)(1,1)(1,1)出发到它不经过其它棋子的方案数. 于是我们假设(h,w)(h,w)(h,w)有一个棋子,求出它的fff值就可以 ...
随机推荐
- CSS:水平居中与垂直居中
CSS居中算是一个比较基础的问题,在实际运用中,需要考虑到的一般是两种情况,一种是主要是表现为文字,图片等行内元素的居中,一种是指 div 等块级标签元素的居中. 水平居中 1.行内元素 行内元素(主 ...
- Topcoder SRM 668 DIV 2
VerySecureEncryption 模拟 题意: 给你个串message,然后一个置换key,输出置换K次后的结果. 题解: 直接模拟就好. 代码: #include<iostream&g ...
- STM32命名
STM32产品命名 示例: STM32 F 100 C 6 T 6 B XXX 1 2 3 4 5 6 7 8 9 从上面的料号可以看出以下信息: ST品牌ARM Cortex-Mx系列内核32位超值 ...
- [转] VS2015中跑OpenGL红宝书第八版的第一章示例代码,运行
Ori Article Link OpenGL的东西快忘光了,把角落的第八版红宝书拿出来复习一下 从书中的地址下了个示例代码结果新系统(Win10+VS2015)各种跑不起来,懊恼之后在网上疯狂搜索资 ...
- html使用示例
select标签 <select name="Area" id="Area" class="sel"> <option v ...
- ylbtech-czgfh(规范化)-数据库设计
ylbtech-DatabaseDesgin:ylbtech-czgfh(规范化)-数据库设计 DatabaseName:czgfh(财政规范化) Model:账户模块.系统时间设计模块.上报自评和审 ...
- window脚本命令学习(转)
批处理文件是无格式的文本文件,它包含一条或多条命令.它的文件扩展名为 .bat 或 .cmd.在命令提示下键入批处理文件的名称,或者双击该批处理文件,系统就会调用Cmd.exe按照该文件中各个命令出现 ...
- 下载SCI论文
今天帮汪博下了一下午SCI论文,见到了很多不知道的网站.顺便了解了一下: 首先进学校图书馆的网站,然后选择 WOS核心合集(含SCIE.SSCI.A&HCI.CPCI数据库) ---&g ...
- 2016.10.18kubernetes 的8080和6443端口的区别与联系
由看过的资料知道,可以使用kubectl,client libraries和REST请求来访问api. 来自官方资料: By default the Kubernetes APIserver se ...
- IO流中文件和文件夹的删除程序举例
/* * 删除功能(无论是文件夹还是文件都是用delete方法,仅仅能一级一级的删除.):public boolean delete() * * 注意: * A:假设你创建文件或者目录忘了写盘符路径, ...