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 ...
随机推荐
- 在HCI层ACL Connection的建立
一.概述 上一篇博文介绍的是inquiry的整个过程中HCI层的command和event.在寻找到有效的远端蓝牙设备后,开始建立ACL连接,这里仅仅反应HCI层的数据包,对于LM层和Base ...
- go安装windows源码
直接安装就好,下面是安装地址http://pan.baidu.com/s/1gdDFi9t
- 利用 libiconv 实现汉字编码 utf-8 格式 和 gbk格式的相互转换
参考文章:http://jimmee.iteye.com/blog/2174693 关于windows上编译libiconv的库,请参见:http://www.cnblogs.com/tangxin- ...
- php 显示某一个时间相当于当前时间在多少秒前,多少分钟前,多少小时前
/* *function:显示某一个时间相当于当前时间在多少秒前,多少分钟前,多少小时前 *timeInt:unix time时间戳 *format:时间显示格式 */ public function ...
- [转]ANDROID L——Material Design详解(动画篇)
转载请注明本文出自大苞米的博客(http://blog.csdn.net/a396901990),谢谢支持! 转自:http://blog.csdn.net/a396901990/article/de ...
- 【转】关于Android资源文件中出现百分号的问题
关于Android资源文件中出现百分号的问题 分类: Android JAVA2014-08-01 16:53 1345人阅读 评论(0) 收藏 举报 ANDROID格式化资源文件 目录(?)[+ ...
- The include feature of SQL Server Index
1. Why we need the index 'include' feature? For SQLServer , the length of all the index key have a l ...
- iOS:详细的正则表达式
1.简介: 在项目中,正则的使用是很普遍的,例如登录账号和密码(手机号.邮箱等).用到的方法就是谓词对象过滤:NSPredicate. 2.什么是正则表达式: 正则表达式,又称正规表示法,是对字符串操 ...
- Android Studio IDE 主题设置
1.界面主题设置,如下图: 2.代码字体设置,如下图:
- Bugfree实用心得_转
转自:http://blog.csdn.net/benkaoya/article/details/8719257 本博下有许多实用技巧 1. 什么是问题跟踪系统 问题跟踪系统(Issue Tracki ...