agc001E - BBQ Hard(dp 组合数)
题意
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 组合数)的更多相关文章
- 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 ...
- [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 ...
- noj 2033 一页书的书 [ dp + 组合数 ]
传送门 一页书的书 时间限制(普通/Java) : 1000 MS/ 3000 MS 运行内存限制 : 65536 KByte总提交 : 53 测试通过 : 1 ...
- 【区间dp+组合数+数学期望】Expression
https://www.bnuoj.com/v3/contest_show.php?cid=9148#problem/I [题意] 给定n个操作数和n-1个操作符,组成一个数学式子.每次可以选择两个相 ...
- [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 ...
- hdu 3944 DP? 组合数取模(Lucas定理+预处理+帕斯卡公式优化)
DP? Problem Description Figure 1 shows the Yang Hui Triangle. We number the row from top to bottom 0 ...
- Contest 20140708 testB dp 组合数
testB 输入文件: testB.in 输出文件testB.out 时限3000ms 问题描述: 定义这样一个序列(a1,b1),(a2,b2),…,(ak,bk)如果这个序列是方序列的话必须满足 ...
- HDU 5396 Expression(DP+组合数)(详解)
题目大意: 给你一个n然后是n个数. 然后是n-1个操作符,操作符是插入在两个数字之间的. 由于你不同的运算顺序,会产生不同的结果. 比如: 1 + 1 * 2 有两种 (1+1)*2 或者 ...
- LightOJ - 1246 Colorful Board(DP+组合数)
http://lightoj.com/volume_showproblem.php?problem=1246 题意 有个(M+1)*(N+1)的棋盘,用k种颜色给它涂色,要求曼哈顿距离为奇数的格子之间 ...
随机推荐
- hdu1403(后缀数组模板)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1403 题意: 给出两个字符串, 求他们的最长公共子串 思路: 两个字符串的最长公共子串长度显然就是两个 ...
- jmeter - 录制web网页
1. 打开JMeter工具 创建一个线程组(右键点击“测试计划”--->“添加”---->“线程组”) 创建一个http代理服务器(右键点击“工作台”--->“添加”-- ...
- Spark大数据处理 之 从WordCount看Spark大数据处理的核心机制(2)
在上一篇文章中,我们讲了Spark大数据处理的可扩展性和负载均衡,今天要讲的是更为重点的容错处理,这涉及到Spark的应用场景和RDD的设计来源. Spark的应用场景 Spark主要针对两种场景: ...
- Orcale创建函数(function)
Oraclec创建函数的语法规则 create or replace function 函数名 (参数名1 参数类型,参数名2 参数类型) return number is Result num ...
- luogu1210 回文检测
Manacher 正确读法:抹内A撤(马拉车) (跟着假硕学英语) 我们把原来的字符串,通过玄学处理,变成只留下字母,且每两个字母之间有一个奇怪的字符的那种Manacher专用字符串. 建立双射关系f ...
- EM最大期望算法
[简介] em算法,指的是最大期望算法(Expectation Maximization Algorithm,又译期望最大化算法),是一种迭代算法,在统计学中被用于寻找,依赖于不可观察的隐性变量的概率 ...
- spring boot 1.4.2.RELEASE+Thymeleaf+mybatis 集成通用maper,与分页插件:
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot ...
- import与from...import...的区别
from ... import ... 的用法和直接import的区别: 1.直接使用import时,如果需要使用到导入模块内的属性和方法,必须使用模块名.属性和模块名.方法的方式进行调用 2.使用f ...
- CodeForces - 359C-Prime Number
Simon has a prime number x and an array of non-negative integers a1, a2, ..., an. Simon loves fracti ...
- 南昌大学航天杯第二届程序设计竞赛校赛网络同步赛 I
链接:https://www.nowcoder.com/acm/contest/122/I来源:牛客网 题目描述 小q最近在做一个项目,其中涉及到了一个计时器的使用,但是笨笨的小q却犯难了,他想请你帮 ...