【题解】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(容斥+格路问题)的更多相关文章

  1. 【CF559C】 Gerald and Giant Chess(计数,方案数DP,数论)

    题意:给出一个棋盘为h*w,现在要从(1,1)到(h,w),其中有n个黑点不能走,问有多少种可能从左上到右下 (1 ≤ h, w ≤ 105, 1 ≤ n ≤ 2000),答案模10^9+7 思路:从 ...

  2. CF559C Gerald and Giant Chess

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

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

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

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

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

  9. 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值就可以 ...

随机推荐

  1. Ansible之Playbook详解

    1.Playbook详解 playbook是一个非常简单的配置管理和多主机部署系统,可以定制配置,可以按照指定的操作步骤有序执行,支持同步和异步方式. 核心元素 Hosts:主机 Tasks:任务,由 ...

  2. PHP的按位运算符是什么意思

    按位运算符是什么意思? 按位运算符(Bitwise Operators)是用于对涉及单个位操作的位模式或二进制数字执行位操作的运算符. 按位运算符可以用于: 1.通信堆栈,其中标头中的各个位附加到数据 ...

  3. php 经验之谈

    导出excel中文名乱码(保存文件名): hpexcel导出Excel文件时有两个主要的过程: 1.定义文件名 2.填充Excel数据 这两个过程中可能会出现一些乱码问题,下面我来说一下解决办法: 解 ...

  4. Jenkins introduction

    http://birdinroom.blog.51cto.com/7740375/1342897 https://www.ibm.com/developerworks/cn/java/j-lo-jen ...

  5. Python标准库:1. 介绍

    标准库包括了几种不同类型的库. 首先是那些核心语言的数据类型库,比方数字和列表相关的库.在核心语言手冊里仅仅是描写叙述数字和列表的编写方式,以及它的排列,而未定义它的语义. 换一句话说,核心语言手冊仅 ...

  6. Win7如何修复开机画面

    将下面文件保存为"修复Win7开机画面.bat"双击运行即可   bcdedit /set {current} locale zh-CN    

  7. Python setup.py和MANIFEST.in文件

    Setup.py文件 from setuptools import setup from codecs import open # 第三方依赖包及版本号 requires = ['beautifuls ...

  8. 分享个免费的货币汇率API

    先上API文档链接:https://www.juhe.cn/docs/api/id/23,支持人民币牌价.外汇汇率查询:数据仅供参考,交易时以银行柜台成交价为准. 人民币牌价 接口地址:http:// ...

  9. (三)初识jQuery

    进入jQuery官网:http://jquery.com/ 点击Download jQuery v3.1.1--->下载最新版本的jQuery版本--->放到你需要引入jQuery的文件中 ...

  10. ASP.NET MVC 扩展自定义视图引擎支持多模板&动态换肤skins机制

    ASP.NET  mvc的razor视图引擎是一个非常好的.NET  MVC 框架内置的视图引擎.一般情况我们使用.NET MVC框架为我们提供的这个Razor视图引擎就足够了.但是有时我们想在我们的 ...