【题解】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值就可以 ...
随机推荐
- [BZOJ3212][POJ3468]A Simple Problem with Integers
题目大意: 维护一个长度为$n(n\leq100000)$的数列,支持区间加.区间求和两种操作,操作共$m(m\leq100000)$次. 思路: Splay区间操作. #include<cst ...
- supervisor开机自启动方法
配置service类型服务 #!/bin/bash # # supervisord This scripts turns supervisord on # # Author: Mike McGrath ...
- 如何查看linux版本 如何查看LINUX是多少位
一.如何得知自己正在使用的linux是什么版本呢,下面的几种方法将给你带来答案! 1. 查看内核版本命令: 1) [root@q1test01 ~]# cat /proc/version Linux ...
- Linux 正则表达式 vi, grep, sed, awk
1. vi 表示内容的元字符 模式 含义 . 匹配任意字符 [abc] 匹配方括号中的任意一个字符.可以使用-表示字符范围,如[a-z0-9]匹配小写字母和阿拉伯数字. [^abc] 在方 ...
- maven 配置jetty插件
<build> <finalName>shiroweb</finalName> <plugins> & ...
- AutoIT V3如何修改字体
1 如图所示,文字很小,阅读和编写多很吃力. 2 按住Ctrl,鼠标滚轮上下滚动可以改变字体大小. 3 如何修改界面的字体,比如改为微软雅黑的字体,现在还没有一个好的解决方案,大家先将就着用吧 ...
- 应用程序之Xib自定义Cell
效果展示 结构分析 代码实现 一.效果展示 二.结构分析 1⃣️首先我们让我们的控制器不再继承UIViewController,而是继承UITableViewController.这样就直接遵守了de ...
- PHP增加$_ENV变量
在日常开发过程中,我们常常会将一些系统或模块配写在配置文件里.这样便于程序维护与修改.通常的配置文件有.ini , .xml等.配置文件的好处在于:1,便于管理.2,可读性高.但是,使用配置文件也会有 ...
- Linux禁止Ctrl+Alt+Del重新启动
方法1:改动/etc/inittab 屏蔽 ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now 或者删除改行内容 保存退出 适用对象:RedHat4.8 ...
- sprint3 【每日scrum】 TD助手站立会议第六天
站立会议 组员 昨天 今天 困难 签到 刘铸辉 (组长) 在添加日程类型处添加了选择闹钟间隔多长时间相应,并写了闹钟运行的类 在日历各个事件上都增加闹钟显示,并将数据传递给日程和时间表 感觉跟楠哥在设 ...