这场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. Jquery手册

    1.jQuery 选择器: 选择器 实例 选取 * $("*") 所有元素 #id $("#lastname") id="lastname" ...

  2. libopencv_highgui.a(window_gtk.cpp.o): undefined reference to symbol 'g_type_check_instance_is_a'

    libopencv_highgui.a(window_gtk.cpp.o): undefined reference to symbol 'g_type_check_instance_is_a' 尝试 ...

  3. 【C51】单片机芯片之——图解74HC595

    第一部部分用于快速查阅使用,详细的使用见文章第二部分 引脚图

  4. HBASE的读写以及client API

    一:读写思想 1.系统表 hbase:namespace 存储hbase中所有的namespace的信息 hbase:meta rowkey:hbase中所有表的region的名称 column:re ...

  5. C++ 安全字符串拼接

    #include <stdio.h> #include <stdint.h> #include <stdarg.h> #if defined(__GNUC__) # ...

  6. Insecure world writable dir /usr/local in PATH, mode 040777

    /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/universal-darwin14/rbconfi ...

  7. table tricks

  8. MySQL学习笔记——复制的实现原理

    1.三个线程 MYSQL复制是从主服务器复制到一个或多个从服务器的异步过程,在主服务器与从服务器之间实现整个复制过程主要由三个线程来实现,其中一个线程I\O在主服务器器端,另两个线程(SQL线程和I\ ...

  9. SQL-Server2008 数据库发布订阅

    参考博客园文章http://www.cnblogs.com/tyb1222/archive/2011/05/31/2064944.html 添加安全数据库 更改数据库名称 SQL语句 select @ ...

  10. shell中如何判断某一命令是否存在

    参考: http://www.cnblogs.com/tuzkee/p/3755230.html https://segmentfault.com/q/1010000000156870 http:// ...