[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.组合数计 ...
随机推荐
- Centos7最小安装化后安装图形界面
首先需要对系统进行更新 yum -y upgrade 然后安装桌面组件包 ,在命令行下输入下面的命令来安装 Gnome 包 yum groupinstall "GNOME Desktop&q ...
- QTP 11 补丁大全
原文: http://relevantcodes.com/qtp-11-0-patches/ Patch Link Details Support for Chrome 19 QTPWEB_00102 ...
- C#—Nhibernate使用教程
本篇文章,让我们一起来探索Nhibernate.首先我们去搜索Nhibernate下载地址,如下链接所示.该版本可能是最新版,我下载的4.0.4.GA.其中GA意思我没搞清楚.不过应该不重要.http ...
- c++静态成员变量初始化时不受访问权限控制
1.要在类外初始化,const 成员变量才能在类内初始化 2.初始化在类外,而不在main函数内 class A{ private: string name; A(){ name = "a& ...
- 20190928 On Java8 第二十三章 注解
第二十三章 注解 定义在 java.lang 包中的5种标准注解: @Override:表示当前的方法定义将覆盖基类的方法.如果你不小心拼写错误,或者方法签名被错误拼写的时候,编译器就会发出错误提示. ...
- 第九届蓝桥杯A组第三题: 乘积尾零
标题:乘积尾零如下的10行数据,每行有10个整数,请你求出它们的乘积的末尾有多少个零?5650 4542 3554 473 946 4114 3871 9073 90 4329 2758 7949 6 ...
- FZUOJ-2275 Game
Problem 2275 Game Accept: 159 Submit: 539 Time Limit: 1000 mSec Memory Limit : 262144 KB Pro ...
- call apply bind的使用方法和区别
call 1.改变this指向 2.执行函数 3.传参 var obj={}; function fun(a,b){ console.log(a,b,this); } fun(1,2); / ...
- vue-fiters过滤器的使用
1.定义过滤器 2.使用过滤器 ...... <el-table-column prop="user_gender" align="center" lab ...
- ASE Backend Alpha Sprint Review
[Backend] Alpha Review展示博客 团队成员介绍:仅限于Alpha阶段有贡献的成员. 典型场景描述:描述并说明你们认为的产品面向的典型场景. 团队管理与协作:包括但不限于团队内部如何 ...