题意

题目链接

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. 安装Scrapy报错 error: Microsoft Visual C++ 14.0 is required解决方法

    [问题背景]:在Windows 10系统,pip install Scrapy,报错error: Microsoft Visual C++ 14.0 is required,还有提示Twisted需要 ...

  2. P4013 数字梯形问题

    \(\color{#0066ff}{题目描述}\) 给定一个由 \(n\) 行数字组成的数字梯形如下图所示. 梯形的第一行有 \(m\) 个数字.从梯形的顶部的 \(m\) 个数字开始,在每个数字处可 ...

  3. 并查集【洛谷P1197】 [JSOI2008]星球大战

    P1197 [JSOI2008]星球大战 题目描述 很久以前,在一个遥远的星系,一个黑暗的帝国靠着它的超级武器统治着整个星系. 某一天,凭着一个偶然的机遇,一支反抗军摧毁了帝国的超级武器,并攻下了星系 ...

  4. DP【洛谷P2134】 百日旅行

    [洛谷P2134] 百日旅行 题目背景 重要的不是去哪里,而是和你在一起.--小红 对小明和小红来说,2014年7月29日是一个美好的日子.这一天是他们相识100天的纪念日. (小明:小红,感谢你2场 ...

  5. POJ1664 放苹果 (母函数)

    放苹果 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 37515   Accepted: 23090 Description ...

  6. flask 坑

    no python application found, check your startup logs for errors 日志里面报类似于“Mon Mar 23 10:26:49 2015 – ...

  7. 【STL基础】vector

    vector 构造函数: //default: vector<T> v; //空的vector //fill: vector<T> v(n); //n个元素的vector,元素 ...

  8. [JavaScript] New-Agnostic Constructor Pattern

    function User (name, password) { var self = this instanceof User ? this : new User(); if (name != nu ...

  9. Mybatis学习笔记(九) —— Mybatis逆向工程

    一.什么是Mybatis逆向工程? 简单的解释就是通过数据库中的单表,自动生成java代码. 我们平时在使用Mabatis框架进行Web应用开发的过程中,需要根据数据库表编写对应的Pojo类和Mapp ...

  10. 关闭 chrome 自动填充

    <input name="uname" type="text" required autocomplete="off" class=& ...