这场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的更多相关文章

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

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

  3. 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)不经过坏点有多少条路径. 先把这些坏点排 ...

  4. Codeforces Round #313 (Div. 1) A. Gerald's Hexagon

    Gerald's Hexagon Problem's Link: http://codeforces.com/contest/559/problem/A Mean: 按顺时针顺序给出一个六边形的各边长 ...

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

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

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

  8. 【打CF,学算法——三星级】Codeforces Round #313 (Div. 2) C. Gerald&#39;s Hexagon

    [CF简单介绍] 提交链接:http://codeforces.com/contest/560/problem/C 题面: C. Gerald's Hexagon time limit per tes ...

  9. Codeforces Round #313 (Div. 2) C. Gerald&#39;s Hexagon(补大三角形)

    C. Gerald's Hexagon time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

随机推荐

  1. (IOS)Swift2.0 Radio 程序分析

    本文主要分享下楼主在学习Swift编程过程中,对GitHub上的一个开源项目Swift Radio的研究心得. 项目地址:https://github.com/swiftcodex/Swift-Rad ...

  2. CLH锁 、MCS锁

    一.引文 1.1 SMP(Symmetric Multi-Processor) 对称多处理器结构,指服务器中多个CPU对称工作,每个CPU访问内存地址所需时间相同.其主要特征是共享,包含对CPU,内存 ...

  3. oracle常用的SQL语句

    一些常用的SQL语句: --建表 create table adolph (id number(10,0),              name varchar2(20),              ...

  4. C/C++ 排序&&查找算法(面试)

    一.排序 1.冒泡排序 void BubbleSort(int array[],int n) { ; ; ; ; ;i<n - ;i++) /*外循环控制排序的总趟数*/ { flag = ; ...

  5. Sass和Compass制作雪碧图

    1.安装好了sass与compass之后设置一个配置文件 2.新增一个雪碧图文件夹用来存放将要合并的图片例如color文件夹 3.@import命令引用 .Compass看到@import指令的参数为 ...

  6. Magento Table Rate运费国家代码汇总

    Magento Table Rate是三种内置未调用第三方API运费方式中最强大的一个.通过设置国家,区域,邮编,价格来划分不同的运费等级.该方式基本能够满足轻量级的B2C商城的运费模式.这里收集下国 ...

  7. detailsview 样式小问题

    detailsview不显示表头,设置HeaderText=""就可以,不知道为什么,如果有值,其他方式都没有调好! 内网格显示为0,Gridlines="None&qu ...

  8. JS之script标签

    1.script标签的位置 script标签可以在head标签中,也可以在body标签中 2.async属性 async的目的是不让页面等待js文件的下载和执行,从而异步加载页面中的其他内容.只支持外 ...

  9. c#上传文件(一)使用 .net 控件上传文件

    1.html代码: <body> <form id="form1" runat="server"> <div> <as ...

  10. java 中间件

    先说中间件:非底层操作系统软件.非业务应用软件,不是直接给最终用户使用的,不能直接给客户带来价值的软件,统称中间件.常见的有如下几种:服务中间件.集成中间件.数据中间件.消息中间件.安全中间件. 其中 ...