题意

题目链接

Sol

非常妙的一道题目。

首先,我们可以把\(C_{a_i + b_i + a_j + b_j}^{a_i + a_j}\)看做从\((-a_i, -b_i)\)走到\((a_j, b_j)\)的方案数

然后全都放的一起dp,\(f[i][j]\)表示从\((i, j)\)之前的所有点到\((i, j)\)的方案数

减去重复的即可


#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10, mod = 1e9 + 7;
inline int read() {
int x = 0, f = 1; char c = getchar();
while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
int N, a[MAXN], b[MAXN], f[5001][5001], fac[10001], ifac[10001];
int add(int x, int y) {
if(x + y < 0) return x + y + mod;
return x + y > mod ? x + y - mod : x + y ;
}
int mul(int x, int y) {
return 1ll * x * y % mod;
}
int fastpow(int a, int p) {
int base = 1;
while(p) {
if(p & 1) base = mul(base, a);
a = mul(a, a); p >>= 1;
}
return base;
}
void init() {
fac[0] = 1;
for(int i = 1; i <= 8000; i++) fac[i] = mul(i, fac[i - 1]);
ifac[8000] = fastpow(fac[8000], mod - 2);
for(int i = 8000; i; i--) ifac[i - 1] = mul(i, ifac[i]);
}
int id(int x) {
return 2001 + x;
}
int C(int N, int M) {
return 1ll * fac[N] * ifac[N - M] % mod * ifac[M] % mod;
}
main() {
// freopen("a.in", "r", stdin);
init();
N = read();
for(int i = 1; i <= N; i++) a[i] = read(), b[i] = read(), f[id(-a[i])][id(-b[i])]++;
for(int i = 1; i <= 4221; i++)
for(int j = 1; j <= 4221; j++)
f[i][j] = add(f[i][j], add(f[i - 1][j], f[i][j - 1]));
// printf("%d %d %d\n", i, j, f[i][j]);
int sum = 0;
for(int i = 1; i <= N; i++)
sum = add(sum, add(f[id(a[i])][id(b[i])], -C(a[i] + b[i] + a[i] + b[i], a[i] + a[i])));
//这里会到8000.。。
sum = 1ll * sum * 500000004ll % mod;
cout << sum % mod;
return 0;
}
/*
8
2000 2000
1999 1998
1 1
1 1
2 1
1 3
2 1
3 3
*/

agc001E - BBQ Hard(dp 组合数)的更多相关文章

  1. AtCoder AGC001E BBQ Hard (DP、组合计数)

    题目链接: https://atcoder.jp/contests/agc001/tasks/agc001_e 题解: 求\(\sum^n_{i=1}\sum^n_{j=i+1} {A_i+A_j+B ...

  2. [Agc001E] BBQ Hard

    [Agc001E] BBQ Hard 题目大意 给定\(n\)对正整数\(a_i,b_i\),求\(\sum_{i=1}^{n-1} \sum_{j=i+1}^n \binom{a_i+b_i+a_j ...

  3. noj 2033 一页书的书 [ dp + 组合数 ]

    传送门 一页书的书 时间限制(普通/Java) : 1000 MS/ 3000 MS          运行内存限制 : 65536 KByte总提交 : 53            测试通过 : 1 ...

  4. 【区间dp+组合数+数学期望】Expression

    https://www.bnuoj.com/v3/contest_show.php?cid=9148#problem/I [题意] 给定n个操作数和n-1个操作符,组成一个数学式子.每次可以选择两个相 ...

  5. [agc001E]BBQ Hard[组合数性质+dp]

    Description 传送门 Solution 题目简化后要求的实际上是$\sum _{i=1}^{n-1}\sum _{j=i+1}^{n}C^{A[i]+A[j]}_{A[i]+A[j]+B[i ...

  6. hdu 3944 DP? 组合数取模(Lucas定理+预处理+帕斯卡公式优化)

    DP? Problem Description Figure 1 shows the Yang Hui Triangle. We number the row from top to bottom 0 ...

  7. Contest 20140708 testB dp 组合数

    testB 输入文件: testB.in  输出文件testB.out 时限3000ms 问题描述: 定义这样一个序列(a1,b1),(a2,b2),…,(ak,bk)如果这个序列是方序列的话必须满足 ...

  8. HDU 5396 Expression(DP+组合数)(详解)

    题目大意: 给你一个n然后是n个数. 然后是n-1个操作符,操作符是插入在两个数字之间的. 由于你不同的运算顺序,会产生不同的结果. 比如: 1 + 1 * 2 有两种  (1+1)*2   或者   ...

  9. LightOJ - 1246 Colorful Board(DP+组合数)

    http://lightoj.com/volume_showproblem.php?problem=1246 题意 有个(M+1)*(N+1)的棋盘,用k种颜色给它涂色,要求曼哈顿距离为奇数的格子之间 ...

随机推荐

  1. P3398 仓鼠找sugar 树上路径相交判断

    \(\color{#0066ff}{题目描述}\) 小仓鼠的和他的基(mei)友(zi)sugar住在地下洞穴中,每个节点的编号为1~n.地下洞穴是一个树形结构.这一天小仓鼠打算从从他的卧室(a)到餐 ...

  2. 「洛谷P3768」简单的数学题 莫比乌斯反演+杜教筛

    题目链接 简单的数学题 题目描述 输入一个整数n和一个整数p,你需要求出 \[\sum_{i=1}^n\sum_{j=1}^n (i\cdot j\cdot gcd(i,j))\ mod\ p\]  ...

  3. opencv-机器学习章节介绍

    概念 1.机器学习:训练样本,特征,分类器.最需要的是特征. 2.深度学习:海量的训练数据,神经网络.最需要的是样本多一些. 特征 Hear特征一般是人脸检测用到的 Hog特征一般是物体检测用到的 分 ...

  4. 2018-2019-2 20165320 《网络对抗技术》 Exp6 信息搜集与漏洞扫描

    2018-2019-2 20165320 <网络对抗技术> Exp6 信息搜集与漏洞扫描 一.实践目标 掌握信息搜集的最基础技能与常用工具的使用方法. 二.实践内容 1.各种搜索技巧应用 ...

  5. 弃用serv-u,改用 Xlight FTP

    Serv-u 强大,设置也较麻烦一点,针对serv-u的攻击也很丰富.试用期只有一个月,破解版的用着也不放心 Xlight FTP 设置简单,个人版免费使用,感觉良好!

  6. 2-29 while

    do while for

  7. Camtasia Studio 8卸载不了解决方法

    Win7:%ProgramData%\TechSmith\Camtasia Studio 8\RegInfo.iniWinXP:”%AllUsersProfile%\Application Data\ ...

  8. 10-排序6 Sort with Swap(0, i) (25 分)

    Given any permutation of the numbers {0, 1, 2,..., N−1}, it is easy to sort them in increasing order ...

  9. connecting-to-github-with-ssh

    https://help.github.com/articles/connecting-to-github-with-ssh/ 创建ssh密钥后,从github clone仓库到本地出现permiss ...

  10. build-helper-maven-plugin

    <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven ...