[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.组合数计 ...
随机推荐
- nacos 使用 servlet 异步处理客户端配置长轮询
config 客户端 ClientWorker#ClientWorker 构造方法中启动定时任务 ClientWorker.LongPollingRunnable 长轮询的任务,在 run 方法的结尾 ...
- 阶段1 语言基础+高级_1-3-Java语言高级_04-集合_04 数据结构_5_数据结构_红黑树
生活中的树和计算机中的树.计算机的树是倒着的
- 测开之路九十二:css之背景色和背景
引用css 设置背景色: 背景图片 整个页面的背景图片 图片当局部背景图 也可以简写 css /* css基本样式 */ /* 设置p标签的文字前景色.背景色 */p{ /*字体颜色为蓝色*/ col ...
- request.getParameter
request.getParameter(),该API针对的是 form表单entype的值为 application/x-www-form-urlencoded(默认值), 或者参数跟在地址栏上us ...
- vue复合组件----注册表单
<!doctype html> <html> <head> <meta charset="UTF-8"> <title> ...
- 【HANA系列】SAP HANA启动出现ERROR
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[HANA系列]SAP HANA启动出现ERRO ...
- Linux命令整理 - 通用版
通用版 - 系统架构 /dev 设备文件夹 null 有去无回 mouse /sbin 系统管理必备程序 cfdisk.dhcpcd.dump.e2fsck.fdisk.halt.ifconfig.i ...
- 精灵图和base64如何选择
Css Sprites: 介绍: Css Sprites(雪碧图或css精灵),是网页图片处理的一种方式,它允许你将一个页面涉及到的所有零星图片都包含到一张大图中去,这样一来,当访问该页面时,载入的图 ...
- (4.12)mysql备份还原——mysql逻辑备份之mysqldump
关键词:mysql逻辑备份介绍,mysqldump,mysqldump最佳实践 我的相关文章:https://www.cnblogs.com/gered/p/9721696.html 正文 1.mys ...
- Java RPC 分布式框架性能大比拼,Dubbo排老几?
来源:http://985.so/aXe2 Dubbo 是阿里巴巴公司开源的一个Java高性能优秀的服务框架,使得应用可通过高性能的 RPC 实现服务的输出和输入功能,可以和 Spring框架无缝集成 ...