Codeforces #313 (Div. 1) C. Gerald and Giant Chess dp 组合数 逆元
来源:互联网 发布:上古5白雪sg捏脸数据 编辑:程序博客网 时间:2024/05/17 09:48
描述
有一个
思路
一开始的思路是容斥原理,但是公式推了半天都推不出来。最后经过指导得出了解法。
记从
记
直接算
那么
于是我们要计算的是
code
#include <bits/stdc++.h>using namespace std;const int MOD = 1E9+7;const int maxn=300005;long long fac[maxn];long long inv[maxn];/*=================================================*/long long power(long long a,long long p) { long long res=1; while(p) { if(p&1) res=(res*a)%MOD; a=(a*a)%MOD; p>>=1; } return res; } long long Inv(long long a) { return power(a,MOD-2); } void init() { fac[0]=inv[0]=1; for(long long i=1;i<300005;i++) { fac[i]=fac[i-1]*i; fac[i]%=MOD; inv[i]=Inv(fac[i]); } } long long C(long long n,long long m) { if(n<0||m<0) return 0; long long res=fac[n]; res%=MOD; res*=inv[m]; res%=MOD; res*=inv[n-m]; res%=MOD; return res;} /*=================================================*/struct Node { int x, y; Node() {} Node(int _x, int _y) { x = _x; y = _y; }}p[2005];bool cmp (Node a, Node b) { if (a.x == b.x) return a.y < b.y; else return a.x < b.x;}int h, w, n;long long res = 0;long long dp[2005];int main () { init(); scanf("%d%d%d", &h, &w, &n); p[0] = Node(h, w); for (int i=1; i<=n; i++) { scanf ("%d%d", &p[i].x, &p[i].y); } sort(p, p+n+1, cmp); dp[0] = C(p[0].x + p[0].y - 2, p[0].x-1); for (int i=1; i<=n; i++) { dp[i] = C(p[i].x - 1 + p[i].y - 1, p[i].x - 1); res = 0; for (int j=0; j<i; j++) { if (p[j].x <= p[i].x && p[j].y <= p[i].y) { res = (res + (dp[j] * C(p[i].x - p[j].x + p[i].y - p[j].y, p[i].x - p[j].x)) % MOD ) % MOD; } } dp[i] = (dp[i] - res + MOD) % MOD; } printf("%d\n", dp[n]); return 0;}
0 0
- Codeforces #313 (Div. 1) C. Gerald and Giant Chess dp 组合数 逆元
- Codeforces 559C Gerald and Giant Chess (dp+组合数+逆元)
- Codeforces Round #313 (Div. 1) C. Gerald and Giant Chess(DP+组合数取模)(好题)
- Codeforces Round #313 (Div. 1) C. Gerald and Giant Chess
- Codeforces Round #313 (Div. 1) C. Gerald and Giant Chess
- codeforces round313 div2E Gerald and Giant Chess dp+组合数
- codeforces 559C Gerald and Giant Chess(dp+组合数学)
- Codeforces 559C Gerald and Giant Chess 组合数学 DP
- Codeforces Round #313 (Div. 1) C - Gerald and Giant Chess dp
- Codeforces Round #313 (Div. 1) C. Gerald and Giant Chess DP
- Codeforces 559C Gerald and Giant Chess(DP+乘法逆元求大组合数)
- Codeforces Round #313 (Div. 2) E. Gerald and Giant Chess 定理Lucas求大组合数
- codeforces 559C|51nod1486 Gerald and Giant Chess(组合数学+逆元)
- 【CodeForces】559C - Gerald and Giant Chess(dp & 逆元 & 容斥原理)
- 【Codeforces Round #313 (Div. 1) C】 CodeForces 559C Gerald and Giant Chess
- Codeforces 560E Gerald and Giant Chess 组合数学+DP
- 【Codeforces Round #313 Div. 1】 559C Gerald and Giant Chess
- codeforces(559C)--C. Gerald and Giant Chess(组合数学)
- OCP-V13-707
- 从全部控件中找指定类型的控件
- 更新xcode7运行程序,报错*** Assertion failure in -[UIApplication _runWithMainScene:transi
- Android Sdk 快速下载,解决下载慢的问题
- WideCharToMultiByte和MultiByteToWideChar函数的用法 (转)
- Codeforces #313 (Div. 1) C. Gerald and Giant Chess dp 组合数 逆元
- Vijos 题目1470 教主的后花园(DP)
- Android 手机上获取物理唯一标识码
- /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.14' not found
- 【VBS脚本教程】:写入记事本文件及输出
- leetcode-110-Balanced Binary Tree
- 《问题与总结》
- Linux下so文件的生成和使用
- Android RecyclerView实现listview效果