C. Gerald and Giant Chess

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/559/problem/C

Description

Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to . Then he measured the length of its sides, and found that each of them is equal to an integer number of centimeters. There the properties of the hexagon ended and Gerald decided to draw on it.

He painted a few lines, parallel to the sides of the hexagon. The lines split the hexagon into regular triangles with sides of 1 centimeter. Now Gerald wonders how many triangles he has got. But there were so many of them that Gerald lost the track of his counting. Help the boy count the triangles.

Input

The first line of the input contains three integers: h, w, n — the sides of the board and the number of black cells (1 ≤ h, w ≤ 105, 1 ≤ n ≤ 2000).

Next n lines contain the description of black cells. The i-th of these lines contains numbers ri, ci (1 ≤ ri ≤ h, 1 ≤ ci ≤ w) — the number of the row and column of the i-th cell.

It is guaranteed that the upper left and lower right cell are white and all cells in the description are distinct.

Output

Print a single line — the remainder of the number of ways to move Gerald's pawn from the upper left to the lower right corner modulo109 + 7.

Sample Input

3 4 2
2 2
2 3

Sample Output

2

HINT

题意

一个n*m的图,让你从左上角走到右下角,有一些点不能经过,问你有多少种方法

题解:

dp[i]表示不经过黑点的方案数

fi=Cxixi+yi−∑(xj<=xi,yj<=yi)C(xi−xj)(xi−xj)+(yi−yj)∗fj

然后一路小跑就好了

http://blog.csdn.net/popoqqq/article/details/46121519

代码

#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
#define maxn 1010000
#define M 10000
#define mod 1000000007
#define eps 1e-9
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************** struct Point
{
long long x,y;
}points[];
bool cmp(Point a,Point b)
{
if(a.x==b.x)
return a.y<b.y;
return a.x<b.x;
}
ll p=mod;
ll fac[maxn];
ll qpow(ll a,ll b)
{
ll ans=;a%=mod;
for(ll i=b;i;i>>=,a=a*a%mod)
if(i&)ans=ans*a%mod;
return ans;
}
ll C(ll n,ll m)
{
if(m>n||m<)return ;
ll s1=fac[n],s2=fac[n-m]*fac[m]%mod;
return s1*qpow(s2,mod-)%mod;
}
ll f[maxn];
int main()
{
fac[]=;
for(int i=;i<maxn;i++)
fac[i]=fac[i-]*i%mod;
int n=read(),m=read(),k=read();
for(int i=;i<=k;i++)
{
points[i].x=read();
points[i].y=read();
points[i].x-=;
points[i].y-=;
}
points[++k].x=n-;
points[k].y=m-;
sort(points+,points+k+,cmp);
for(int i=;i<=k;i++)
{
f[i]=C(points[i].x+points[i].y,points[i].x);
for(int j=;j<i;j++)
{
if(points[j].y<=points[i].y)
{
f[i]+=(p-f[j]*C(points[i].x-points[j].x+points[i].y-points[j].y,points[i].x-points[j].x)%p);
f[i]%=p;
}
}
}
cout<<f[k]%p<<endl;
}

最新文章

  1. 【C#】New操作符所做的事情
  2. apache域名本地映射
  3. 分享几个原生javascript面向对象设计小游戏
  4. eclipse文本编码格式修改为UTF-8 (转)
  5. HDU 3487 Play with Chain(Splay)
  6. 常用库nuget包集合
  7. Win7 Qt4.8.5+QtCreator2.8.0+mingw配置过程
  8. 2016年10月22日 星期六 --出埃及记 Exodus 19:6
  9. Linux编程环境介绍(2) -- shell(Bash) 介绍
  10. 5.5 Function类型
  11. ABP官方文档翻译 3.3 仓储
  12. 我的代码-normalize
  13. Pyhon学习笔记-基础3
  14. 环境部署(一):Linux下安装JDK
  15. socket 995 错误 boost
  16. Andrew Ng-ML-第九&amp;十章-神经网络
  17. CTF-Bugku-分析-信息提取
  18. 【转载】COM 组件设计与应用(十二)——错误与异常处理
  19. python开发socket套接字:粘包问题&amp;udp套接字&amp;socketserver
  20. Python metaclasses

热门文章

  1. [问题解决]同时显示多个Notification时PendingIntent的Intent被覆盖?
  2. RestTemplate中文乱码问题(spring-web3.0.7版本)
  3. 转载: Android开源库V - Layout:淘宝、天猫都在用的UI框架,赶紧用起来吧!
  4. python类中的私有方法
  5. thinkphp辅助方法,数据库操作
  6. js数组基本操作
  7. C#比较时分秒大小,终止分钟默认加十分钟,解决跨天、跨月、跨年的情况
  8. oralce 笔记
  9. MySQL学习笔记:Engine存储引擎
  10. 20165203迭代和JDB测试