[AGC001E]BBQ Hard 组合数学
题目描述
Snuke is having another barbeque party.
This time, he will make one serving of Skewer Meal.
He has a stock of N Skewer Meal Packs. The i-th Skewer Meal Pack contains one skewer, Ai pieces of beef and Bi pieces of green pepper. All skewers in these packs are different and distinguishable, while all pieces of beef and all pieces of green pepper are, respectively, indistinguishable.
To make a Skewer Meal, he chooses two of his Skewer Meal Packs, and takes out all of the contents from the chosen packs, that is, two skewers and some pieces of beef or green pepper. (Remaining Skewer Meal Packs will not be used.) Then, all those pieces of food are threaded onto both skewers, one by one, in any order.
(See the image in the Sample section for better understanding.)
In how many different ways can he make a Skewer Meal? Two ways of making a Skewer Meal is different if and only if the sets of the used skewers are different, or the orders of the pieces of food are different. Since this number can be extremely large, find it modulo 109+7.
Constraints
2≦N≦200,000
1≦Ai≦2000,1≦Bi≦2000
输入
The input is given from Standard Input in the following format:
N
A1 B1
A2 B2
:
AN BN
输出
Print the number of the different ways Snuke can make a serving of Skewer Meal, modulo 109+7.
样例输入
3
1 1
1 1
2 1
- 1
- 2
- 3
- 4
样例输出
26
- 1
提示
The 26 ways of making a Skewer Meal are shown below. Gray bars represent skewers, each with a number denoting the Skewer Meal Set that contained the skewer. Brown and green rectangles represent pieces of beef and green pepper, respectively.
题意:
有n个背包,第i个背包里有一个编号为ii的棍子、aiai个肉和bibi个菜。你可以任选两个不同的背包,把这两个背包里所有的肉和菜都用两根棍子串起来形成一个烤串,问能串出多少种烤串。
当且仅当至少有一根棍子的编号不同或者是肉和菜的数目不同或者是排列方式不同时,称这两种烤串是不同的。
#include <bits/stdc++.h> const int maxn = int(4e4) + , mod = int(1e9) + ;
typedef long long ll;
ll fac[maxn], inv[maxn]; ll power_mod(ll p, ll q) {
ll ret = ;
while (q) {
if (q & ) ret = ret * p % mod;
p = p * p % mod;
q >>= ;
}
return ret;
} void init() {
fac[] = ;
for (int i = ; i <= maxn - ; ++i) fac[i] = fac[i - ] * i % mod;
inv[maxn - ] = power_mod(fac[maxn - ], mod - );
for (int i = maxn - ; i >= ; --i) inv[i] = inv[i + ] * (i + ) % mod;
} ll C(int x, int y) {
return fac[x] * inv[y] % mod * inv[x - y] % mod;
} int n, a[], b[], dp[][]; int main() {
// freopen("in.txt", "r", stdin);
init();
scanf("%d", &n);
for (int i = ; i <= n; i++) {
scanf("%d%d", a + i, b + i);
dp[ - a[i]][ - b[i]]++;
}
for (int i = ; i <= ; i++)
for (int j = ; j <= ; j++) {
dp[i][j] = (dp[i][j] + dp[i - ][j]) % mod;
dp[i][j] = (dp[i][j] + dp[i][j - ]) % mod;
}
ll ans = ;
for (int i = ; i <= n; i++) ans = (ans + dp[ + a[i]][ + b[i]]) % mod;
for (int i = ; i <= n; i++) ans = (ans - C(a[i] + a[i] + b[i] + b[i], a[i] + a[i]) + mod) % mod;
printf("%lld\n", ans * power_mod(, mod - ) % mod);
return ;
}
[AGC001E]BBQ Hard 组合数学的更多相关文章
- [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 ...
- AGC001 E - BBQ Hard 组合数学
题目链接 AGC001 E - BBQ Hard 题解 考虑\(C(n+m,n)\)的组合意义 从\((0,0)\)走到\((n,m)\)的方案数 从\((x,y)\)走到\((x+n,y+m)\)的 ...
- AGC001E BBQ Hard 组合、递推
传送门 题意:给出长度为$N$的两个正整数序列$A_i,B_i$,求$\sum\limits_{i=1}^N \sum\limits_{j=i+1}^N C_{A_i+A_j+B_i+B_j}^{A_ ...
- [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 ...
- agc001E - BBQ Hard(dp 组合数)
题意 题目链接 Sol 非常妙的一道题目. 首先,我们可以把\(C_{a_i + b_i + a_j + b_j}^{a_i + a_j}\)看做从\((-a_i, -b_i)\)走到\((a_j, ...
- 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 ...
- atcoder题目合集(持续更新中)
Choosing Points 数学 Integers on a Tree 构造 Leftmost Ball 计数dp+组合数学 Painting Graphs with AtCoDeer tarja ...
- NOIp2018模拟赛三十八
爆〇啦~ A题C题不会写,B题头铁写正解: 随手过拍很自信,出分一看挂成零. 若要问我为什么?gtmdsubtask! 神tm就一个subtask要么0分要么100,结果我预处理少了一点当场去世 难受 ...
- (浙江金华)Day 1 组合数计数
目录 Day 1 组合计数 1.组合数 (1).C(n,m) 读作n选m,二项式系数 : (2).n个东西里选m个的方案数 不关心选的顺序: (3).二项式系数--->多项式系数: 2.组合数计 ...
随机推荐
- 阶段1 语言基础+高级_1-3-Java语言高级_06-File类与IO流_04 IO字节流_8_字节输入流_InputStream类&FileInputStream
inputStream
- C++ 全面刨析使用指针方法 _new _delete
指针 #include<iostream> using namespace std; int main() { ; int* pn;//声明 int* pn = &avr;//初始 ...
- PAT甲级终结——心得总结
首先报喜一波 第一次考,满分,4道题总共花了2个小时做完,一部分是题简单的原因,一部分也是自己三刷了PAT的心血吧. 刷PAT的经验 神指导: 胡凡-<算法笔记> 神助攻:柳婼的博客,百度 ...
- ceph部署-常用命令
常用命令:1.ceph healthceph -s 2.ceph osd treeceph osd lspoolsceph osd pool [poolname] rbd pg_numceph osd ...
- 【洛谷p1981】表达式求值
题前废话: 咱也不知道咱写了个什么神奇的代码导致_rqy都看不明白它是怎么re掉的, 代码的大致思路是这样的:对于这样一个中缀表达式,先转化成它的后缀表达式的形式,然后利用P1449 后缀表达式 这道 ...
- [hdu6558][CCPC2018吉林D题]The Moon(期望dp)
题目链接 当时年少不懂期望$dp$,时隔一年看到这道题感觉好容易.... 定义状态$dp[i]$表示当前的$q$值为$i$时的期望,则当$q$值为$100$时$dp[100]=100/q$,这时后发现 ...
- 浅谈格雷码(Grey Code)在信息学竞赛中的应用
1.格雷码的概念 1.性质 格雷码(Grey Code),又叫循环二进制码或反射二进制码,是一种编码方式,它的基本特点是任意两个相邻的格雷码只有一位二进制数不同. 常用的二进制数与格雷码间的转换关系如 ...
- Django forms组件的校验
引入: from django import forms 使用方法:定义规则,例: class UserForm(forms.Form): name=forms.CharField(max_lengt ...
- Spring事务嵌套引发的问题--Transaction rolled back because it has been marked as rollback-only
转载https://blog.csdn.net/f641385712/article/details/80445912 读了两边才找到问题
- c# winfrom程序中 enter键关联button按钮
1,关联按钮上的Key事件 在按钮上的keypress,keydown,keyup事件必须要获得焦点,键盘上的键才能有效. private void btnEnt ...