codeforces 559C|51nod1486 Gerald and Giant Chess(组合数学+逆元)
来源:互联网 发布:知世故而不世故 编辑:程序博客网 时间:2024/05/17 23:42
codeforces 559C|51nod1486
题目
有中文题目
思路
http://blog.csdn.net/winddreams/article/details/47058209
这位博主讲的很清楚了,还有逆元的技巧。
(其间还了解了一下Lucas定理
代码
#include <cstdio> #include <cstring> #include <algorithm> using namespace std ; #define LL __int64 const LL MOD = 1e9+7 ; struct node{ LL x , y ; }p[3100]; LL h , w , n ; LL fac[310000] , inv[310000] ; LL sum[3100] ; int cmp(node a,node b) { return a.x < b.x || (a.x == b.x && a.y < b.y) ; } LL pow(LL x,LL k) { LL ans = 1 ; while( k ) { if( k&1 ) ans = ans*x%MOD ; k = k>>1 ; x = (x*x)%MOD ; } return ans ; } void init() { LL i , j , c ; fac[0] = inv[0] = 1 ; for(i = 1 ; i <= h+w ; i++) fac[i] = (fac[i-1]*i)%MOD ; c = max(h,w) ; inv[c] = pow(fac[c],MOD-2) ; for(i = c-1 ; i > 0 ; i--) { inv[i] = inv[i+1]*(i+1)%MOD ; } } int main() { LL i , j ; LL ans ; while( scanf("%I64d %I64d %I64d", &h, &w, &n) != EOF ) { init() ; for(i = 0 ; i < n ; i++) scanf("%I64d %I64d", &p[i].x, &p[i].y) ; p[n].x = h ; p[n++].y = w ; sort(p,p+n,cmp) ; int x1 , y1 , x2 , y2 ; for(i = 0 ; i < n ; i++) { x1 = p[i].x-1 ; y1 = p[i].y-1 ; sum[i] = fac[x1+y1]*inv[x1]%MOD*inv[y1]%MOD ; for(j = 0 ; j < i ; j++) { if( p[j].x <= p[i].x && p[j].y <= p[i].y ) { x2 = x1 - p[j].x+1 ; y2 = y1 - p[j].y+1 ; sum[i] = (sum[i]-fac[x2+y2]*inv[x2]%MOD*inv[y2]%MOD*sum[j]%MOD)%MOD ; if( sum[i] <= 0 ) sum[i] = (sum[i]+MOD)%MOD; } } } printf("%I64d\n", sum[n-1]) ; } return 0 ; }
0 0
- codeforces 559C|51nod1486 Gerald and Giant Chess(组合数学+逆元)
- codeforces(559C)--C. Gerald and Giant Chess(组合数学)
- codeforces 559C Gerald and Giant Chess(dp+组合数学)
- codeforces 559C Gerald and Giant Chess(组合数学)
- Codeforces 559C Gerald and Giant Chess 组合数学 DP
- Codeforces 559C Gerald and Giant Chess (dp+组合数+逆元)
- CF 559C. Gerald and Giant Chess 组合数学+DP
- Codeforces #313 (Div. 1) C. Gerald and Giant Chess dp 组合数 逆元
- codeforces 559C Gerald and Giant Chess
- Codeforces 560E Gerald and Giant Chess 组合数学+DP
- 【CodeForces】559C - Gerald and Giant Chess(dp & 逆元 & 容斥原理)
- Code Forces 559 C. Gerald and Giant Chess(组合数学+dp)
- Codeforces 559C Gerald and Giant Chess(DP+乘法逆元求大组合数)
- Gerald and Giant Chess (CodeForces
- codeforce 559 C Gerald and Giant Chess
- Codeforces 560 E. Gerald and Giant Chess (dp,组合数学)
- CF#313-E. Gerald and Giant Chess-dp+组合数学
- 【DP+组合数学】Codeforces559C[Gerald and Giant Chess]题解
- HTML格式化标签
- 字符串总结
- 【NOIP2016提高A组模拟9.3】树塔狂想曲
- CoordinatorLayout+AppBarLayout+CollapsingToolbarLayout+Toolbar用法小结
- 第一篇文章
- codeforces 559C|51nod1486 Gerald and Giant Chess(组合数学+逆元)
- 一些简单的例子让你在Java中能更好的学习并理解循环结构(1)!
- keepalived+nginx双机热备+负载均衡
- 树塔狂想曲【NOIP2016提高A组模拟9.3】
- 玩转四旋翼无人机(sensor数据融合)
- 快速排序详解
- [Intel汇编-NASM]任务控制以及特权级保护
- 上下界网络流
- 64M内存寻址