[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.组合数计 ...
随机推荐
- VMware 虚拟机的虚拟磁盘编程知识点扫盲之二
目录 目录 前文列表 VDDK 安装 VDDK VixDiskLib VADP 前文列表 VMware 虚拟机的虚拟磁盘编程知识点扫盲之一 VDDK 摘自官方文档:The Virtual Disk D ...
- [Python3] 010 字符串:给你们看看我的内置方法 第二弹
目录 少废话,上例子 1. isidentifier() 2. islower() 3. isnumeric() 4. isprintable() 5. isspace() 6. istitle() ...
- checkbox radio 多次操作失效
checkbox radio 多次操作失效 , 将attr替换为prop $(this).attr('checked',true); $(this).attr('checked',false); $( ...
- CentOS 添加硬盘创建并挂载分区
分区工具介绍: fdisk 创建MBR分区:所支持的最大卷:2T,而且对分区有限制:最多4个主分区或3个主分区加一个扩展分区 gdisk 创建GPT分区:突破MBR 4个主分区限制,每个磁盘最多支持1 ...
- HDU-3665 Seaside
XiaoY is living in a big city, there are N towns in it and some towns near the sea. All these towns ...
- LeetCode102. 二叉树的层次遍历
102. 二叉树的层次遍历 描述 给定一个二叉树,返回其按层次遍历的节点值. (即逐层地,从左到右访问所有节点). 示例 例如,给定二叉树: [3,9,20,null,null,15,7], 3 / ...
- 跨域问题解决----NO 'Access-Control-Allow-Origin' header is present on the requested resource.Origin'http://localhost:11000' is therfore not allowed access'
NO 'Access-Control-Allow-Origin' header is present on the requested resource.Origin'http://localhost ...
- DNS服务的安装
DNS服务器原理及配置 域名讲解 www.baidu.com 完整的域名,通常.来进行分割三个部分:www是主机名,baidu是域名,com是类型 主机名 + 域名 + 类型 构成完整的域名 DNS服 ...
- 了解Greenplum(1)
了解系列废话: 数据管理系统实现,以Greenplum作为课后实验,这里将实验报告贴出来,纯粹灌水. 1.Greenplum架构 如上图所示,GP的基本结构是单master,多slave节点,客户端连 ...
- Pillow6 起步
使用 Image 类 可以使用 Image 模块的 open() 方法加载图片文件: from PIL import Image im = Image.open("hopper.ppm&qu ...