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 ...
随机推荐
- MVC3中几个小知识点
1.ViewBag.Name~ViewBag.name等价,即不区分大小写.在此小心,下次见到不要奇怪,不过最好还是写成一样的比较好. 2.JS字符串不允许有换行符,\'等字符,需提前处理.
- NRF51822之动态广播使用
本教程基于nRF51_SDK_10.0.0_dc26b5e\examples\ble_peripheral\ble_app_uart工程 本教程主要是演示 现在演示通过nus来修改ADV中maufac ...
- 如何将cmd中命令输出保存为TXT文本文件
在使用Windows 中的cmd.exe工具时,有时候我们想要把我们的输入命令及结果保存起来, 但是用复制的方法过于麻烦:有时输出数据条数过大,会造成内容自动滚出屏幕,无法阅读,我们可将命令运行的结果 ...
- javascript值和引用
JavaScript引用指向的是值. 简单值(即标量基本类型值,基本类型值,js中6类,null.undefined.boolean.number.string和symbol)总是通过值复制的方式来赋 ...
- Ajax如何实现跨域问题
一个域名的组成 http:// www . abc.com : 8080 /scripts/jquery.js 协议 子域名 主域名 端口号 请求资源地址 当协议.子域名.主域名.端口号中任意一个不同 ...
- SQL 2008 RAISERROR语法在SQL 2012/2014不兼容问题
原文 旧的RAISERROR语法在SQL 2012不兼容问题 raiserror 写法: SQL 2008: raiserror 55030 'text error' SQL 2012: raiser ...
- Asp.net MVC23 使用Areas功能的常见错误
一般WEB项目都会不同的页面区域,如:用户前台.用户后台.管理员后台. 访问的URL: 用户前台:www.domain.com/home/index 用户后台:www.domain.com/admin ...
- Fatal error: Cannot redeclare tran() (previously declared in
解决方法如下: 1.你该段源码里面是不是有include 或者require 之类的包含其他文件函数 包含的文件里已经有 函数 nw() 的定义 而这段代码里又有nv()的定义 所以出现redecla ...
- HTML5列表、块和布局
一.列表 <ul> <ol> <li> unorder order list ol: type="1 A a I i" start=" ...
- category应用(计算nssting的数量)
// // main.m // 03-分类应用 // // Created by apple on 14-3-18. // Copyright (c) 2014年 apple. All rig ...