Codeforces Round #313 (Div. 1) C. Gerald and Giant Chess
来源:互联网 发布:vb自动处理网页弹框 编辑:程序博客网 时间:2024/06/06 09:09
Link
http://codeforces.com/contest/559/problem/C
Description
Data scope
Solution
显然是容斥原理问题,为此我们把禁止走的格子标号。并且设
那么:
距离解决问题的障碍是项太多。一共有
比如 f(14) 就是不可能的,但是 f(23) 就是可以的。原因嘛……
这就启发我们对每一个点计算一个值
Evaluation
Not bad…
Code
#include <bits/stdc++.h>const int MAXK = 2000 + 5;const int MOD = int(1e9) + 7;std::pair<int, int> ban[MAXK];#define fst first#define sec secondstd::vector<int> g[MAXK];long long dp[MAXK];const int MAXN = int(2e5) + 5;long long fac[MAXN];long long inv_fac[MAXN];int n, m, k;void fac_table() { fac[0] = 1; for (int i = 1; i < MAXN; i++) fac[i] = fac[i - 1] * i % MOD; inv_fac[0] = 1; inv_fac[1] = 1; for (int i = 2; i < MAXN; i++) inv_fac[i] = (MOD - MOD / i) * inv_fac[MOD % i] % MOD; for (int i = 2; i < MAXN; i++) inv_fac[i] = inv_fac[i] * inv_fac[i - 1] % MOD; for (int i = 0; i < MAXN; i++) assert(fac[i] * inv_fac[i] % MOD == 1);}long long pascal(int n, int m) { return fac[n] * (inv_fac[m] * inv_fac[n - m] % MOD) % MOD;}long long calc(int x, int y, int p, int q) { return pascal(p + q - x - y, p - x);}long long calc(int u) { return calc(ban[u].fst, ban[u].sec, n, m);}long long calc(int u, int v) { return calc(ban[u].fst, ban[u].sec, ban[v].fst, ban[v].sec);}int dfs(int u) { if (dp[u] != -1) return dp[u]; dp[u] = calc(u); for (int i = 0; i < g[u].size(); i++) { int v = g[u][i]; dp[u] = (dp[u] + calc(u, v) * (MOD - dfs(v)) % MOD) % MOD; } return dp[u];}int main() { fac_table(); scanf("%d %d %d", &n, &m, &k); for (int i = 0; i < k; i++) { scanf("%d %d", &ban[i].fst, &ban[i].sec); } for (int i = 0; i < k; i++) { for (int j = 0; j < k; j++) { if (i == j) continue; if (ban[j].fst >= ban[i].fst && ban[j].sec >= ban[i].sec) g[i].push_back(j); } } memset(dp, -1, sizeof(dp)); long long res = calc(1, 1, n, m); for (int i = 0; i < k; i++) { res = (res + calc(1, 1, ban[i].fst, ban[i].sec) * (MOD - dfs(i))) % MOD; } printf("%d\n", (int) res); return 0;}
0 0
- Codeforces Round #313 (Div. 1) C. Gerald and Giant Chess
- Codeforces Round #313 (Div. 1) C. Gerald and Giant Chess
- 【Codeforces Round #313 (Div. 1) C】 CodeForces 559C Gerald and Giant Chess
- Codeforces Round #313 (Div. 1) C - Gerald and Giant Chess dp
- 【Codeforces Round #313 Div. 1】 559C Gerald and Giant Chess
- Codeforces Round #313 (Div. 1) C. Gerald and Giant Chess DP
- Codeforces Round #313(div.2) E. Gerald and Giant Chess
- Codeforces Round #313 (Div. 1) C. Gerald and Giant Chess(DP+组合数取模)(好题)
- Codeforces #313 (Div. 1) C. Gerald and Giant Chess dp 组合数 逆元
- [CodeForces] Round #313 Div 2 E / Div 1 C Gerald and Giant Chess 不用容斥的递推组合数学
- Codeforces Round #313 (Div. 2) E. Gerald and Giant Chess 定理Lucas求大组合数
- Codeforces Round #313 (Div. 2)E. Gerald and Giant Chess(Lucas定理+dp)
- Codeforces Round #313 (Div. 2) Problem E - Gerald and Giant Chess
- codeforces 559C Gerald and Giant Chess
- Gerald and Giant Chess (CodeForces
- codeforces(559C)--C. Gerald and Giant Chess(组合数学)
- codeforces 559C Gerald and Giant Chess(dp+组合数学)
- codeforces 559C Gerald and Giant Chess(组合数学)
- android之线性布局,相对布局属性总结
- 练习题
- MPLS基本技术介绍
- POJ1007 解题报告
- 百度富文本编辑器ueditor使用
- Codeforces Round #313 (Div. 1) C. Gerald and Giant Chess
- uva 11324 - The Largest Clique(强联通图+拓扑)
- react-native试玩(12)-iOS中导航栏
- hdu 5015(矩阵快速幂z )
- 同一进程中的线程究竟共享哪些资源
- 四种异步更新Android的方式
- 数学概率问题
- SDK控件篇
- C#中调用matlab