Codeforces Round #313 (Div. 1) C. Gerald and Giant Chess
这场CF又掉分了。。。
这题题意大概就给一个h*w的棋盘,中间有一些黑格子不能走,问只能向右或者向下走的情况下,从左上到右下有多少种方案。
开个sum数组,sum[i]表示走到第i个黑点但是不经过其他黑点的方案数。
式子是sum[i]=c(x[i]+y[i],x[i])-Σ(sum[j]*c(x[i]-x[j]+y[i]-y[j],x[i]-x[j]))。
c(x+y,x)表示从格子(1,1)到(x,y)的方案数(没有黑点)。
因此每个点按x[i]+y[i]的值排个序,然后n^2弄一下他们的拓扑关系,就可以推了。
代码
#include<cstdio>
#include<algorithm>
#include<map>
#include<cstring>
#include<vector>
#include<cmath>
#include<iostream>
#include<string>
#define N 600010
#define M 1010
#define P 1000000007
using namespace std;
struct Q{
int x,y,z;
}a[N];
int h,w,n,i,j;
long long g[N],sum[N];
int exgcd(int a,int b,long long &x,long long &y)
{
long long t;
if (b==)
{
x=;y=;return a;
}
exgcd(b,a%b,x,y);
t=x;
x=y;
y=t-a/b*y;
}
long long cl(int x,int y)
{
long long a,b,z,zz;
z=x+y-;
zz=g[x-]*g[z-x+]%P;
z=g[z];
exgcd(zz,P,a,b);
z=(z*a%P+P)%P;
return z;
}
bool cmp(Q a,Q b)
{
return a.z<b.z;
}
int main()
{
scanf("%d%d%d",&h,&w,&n);
g[]=;
for (i=;i<=;i++)
g[i]=(g[i-]*i)%P;
for (i=;i<=n;i++)
{
scanf("%d%d",&a[i].x,&a[i].y);
a[i].z=a[i].x+a[i].y;
}
a[n+].x=h;a[n+].y=w;a[n+].z=h+w;
sort(a+,a++n+,cmp);
for (i=;i<=n+;i++)
{
sum[i]=cl(a[i].x,a[i].y);
for (j=;j<i;j++)
if ((a[j].x<=a[i].x)&&(a[j].y<=a[i].y))
sum[i]=(sum[i]-sum[j]*cl(a[i].x-a[j].x+,a[i].y-a[j].y+))%P;
}
sum[n+]=(sum[n+]%P+P)%P;
printf("%I64d\n",sum[n+]);
}
Codeforces Round #313 (Div. 1) C. Gerald and Giant Chess的更多相关文章
- 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 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 ...
- Codeforces Round #313 (Div. 2) E. Gerald and Giant Chess (Lucas + dp)
题目链接:http://codeforces.com/contest/560/problem/E 给你一个n*m的网格,有k个坏点,问你从(1,1)到(n,m)不经过坏点有多少条路径. 先把这些坏点排 ...
- Codeforces Round #313 (Div. 1) A. Gerald's Hexagon
Gerald's Hexagon Problem's Link: http://codeforces.com/contest/559/problem/A Mean: 按顺时针顺序给出一个六边形的各边长 ...
- Codeforces Round #313 (Div. 2) C. Gerald's Hexagon 数学
C. Gerald's Hexagon Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/559/pr ...
- Codeforces Round #313 (Div. 1) A. Gerald's Hexagon 数学题
A. Gerald's Hexagon Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/559/p ...
- Codeforces Round #313 (Div. 2) B. Gerald is into Art 水题
B. Gerald is into Art Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/560 ...
- 【打CF,学算法——三星级】Codeforces Round #313 (Div. 2) C. Gerald's Hexagon
[CF简单介绍] 提交链接:http://codeforces.com/contest/560/problem/C 题面: C. Gerald's Hexagon time limit per tes ...
- Codeforces Round #313 (Div. 2) C. Gerald's Hexagon(补大三角形)
C. Gerald's Hexagon time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
随机推荐
- 物联网操作系统HelloX V1.80测试版发布
经过HelloX开发团队近半年的努力,在HelloXV1.79版本基础上,增加许多功能特性,并对V1.79版本的一些特性进行了进一步优化之后,正式形成HelloX V1.80测试版本.经相对充分的测试 ...
- 兼容的获得event
function getEvent(e) { var e=window.event || event; return e.srcElement || e.target; }
- IOS测试程序运行耗时
iOS设备相对于电脑,内存和处理能力有限,所以一段代码或者程序运行的时间需要时刻注意,这里提供两种获取精确时间的方法. 方法一:使用系统时间 NSDate* tmpStartData = [[NSDa ...
- ArcGIS中如何导出单个矢量要素图形
原文:ArcGIS中如何导出单个矢量要素图形 在ARCGIS中载入了一张含有省界的中国地图,是SHP文件.现在我只想要其中一块地区的,实现方法如下: 加入到ArcGIS后,右击图层,打开属性表(att ...
- 创建ArcGIS API for JavaScript的第一个示例程序
原文:创建ArcGIS API for JavaScript的第一个示例程序 在上一篇博客中已经介绍了如何搭建ArcGIS API for JavaScript开发环境,如果您还没有搭建好开发环境的话 ...
- 实现 UISegmentControl 与 UIScrollView的上下级联(分别在相应的方法中加入级联代码)
实现 UISegmentControl 与 UIScrollView的上下级联,需要在 [segmentCtr addTarget:self action:@selector(segmentedCon ...
- GitHub 客户端
GitHub客户端下载官网:https://desktop.github.com/ GitHubFlow:https://guides.github.com/introduction/flow/ 客户 ...
- Java私有构造函数不能阻止继承
下面是一个调用已经私有化的单列的函数的列子. 这里用了静态内部类,关键就是静态内部类可以访问外部类的私有构造函数. 这种算是变种继承吧.前提是可以在原来的单列类里添加代码. class Single ...
- 注册表操作命令和自定义cmd窗口
REM @echo offREM clsREM echo Microsoft Windows 7REM echo ------------------------REM echo Welcome to ...
- jq的核心基础
1.jq代码的风格 jq对象$().css();jQuery().css(); //获取jquery对象 示例$().css('background':'red').css('font-siz ...