题目描述

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:


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 组合数学的更多相关文章

  1. [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 ...

  2. AGC001 E - BBQ Hard 组合数学

    题目链接 AGC001 E - BBQ Hard 题解 考虑\(C(n+m,n)\)的组合意义 从\((0,0)\)走到\((n,m)\)的方案数 从\((x,y)\)走到\((x+n,y+m)\)的 ...

  3. 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_ ...

  4. [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 ...

  5. agc001E - BBQ Hard(dp 组合数)

    题意 题目链接 Sol 非常妙的一道题目. 首先,我们可以把\(C_{a_i + b_i + a_j + b_j}^{a_i + a_j}\)看做从\((-a_i, -b_i)\)走到\((a_j, ...

  6. 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 ...

  7. atcoder题目合集(持续更新中)

    Choosing Points 数学 Integers on a Tree 构造 Leftmost Ball 计数dp+组合数学 Painting Graphs with AtCoDeer tarja ...

  8. NOIp2018模拟赛三十八

    爆〇啦~ A题C题不会写,B题头铁写正解: 随手过拍很自信,出分一看挂成零. 若要问我为什么?gtmdsubtask! 神tm就一个subtask要么0分要么100,结果我预处理少了一点当场去世 难受 ...

  9. (浙江金华)Day 1 组合数计数

    目录 Day 1 组合计数 1.组合数 (1).C(n,m) 读作n选m,二项式系数 : (2).n个东西里选m个的方案数 不关心选的顺序: (3).二项式系数--->多项式系数: 2.组合数计 ...

随机推荐

  1. Linux随笔 - vi/vim 编辑器显示行号

    显示行号 1. 打开vi 编辑器 2. 输入  :set number 3. 回车 关闭行号显示 1. 打开vi 编辑器 2. 输入  :set nonumber 3. 回车 行号在每次打开 vi/v ...

  2. Delphi XE2 之 FireMonkey 入门(22) - 数据绑定: BindingSource、BindingName、FindBinding()、Binding[]

    在窗体上添加 TrackBar1.Edit1.Label1, 然后设置属性(可在设计时): procedure TForm1.FormCreate(Sender: TObject); begin   ...

  3. Java面试中hashCode()与equals(Object obj)方法关系的准确回答

    原文地址: https://blog.csdn.net/qq_19260029/article/details/77917925 hashCode()与equals(Object obj)都是Java ...

  4. astype()函数

    1astype()函数可用于转化dateframe某一列的数据类型 如下将dateframe某列的str类型转为int,注意astype()没有replace=True的用法,想要在原数据上修改,要写 ...

  5. [Forward]C++ Properties - a Library Solution

    orig url: https://accu.org/index.php/journals/255 roperties are a feature of a number of programming ...

  6. Selfishness is not living as one wishes to live. it is asking others to live as wishes to live.

    regin: n. 统治; 任期 lap:n. 大腿部. procession: n. 行列,游行 lessen: n. 减少 wade: v. 跋涉 patriotic: adj. 爱国的 Medi ...

  7. 剑指offer--day11

    1.1 题目:字符串的排列:输入一个字符串,按字典序打印出该字符串中字符的所有排列.例如输入字符串abc,则打印出由字符a,b,c所能排列出来的所有字符串abc,acb,bac,bca,cab和cba ...

  8. Echarts使用及动态加载图表数据

    Echarts使用及动态加载图表数据 官网:http://echarts.baidu.com/ 1.文档 2.实例 名词: 1.统计维度(说明数据) 维度就是统计致力于建立一个基于多方位统计(时间.地 ...

  9. jquery点击来回切换

    做个笔记偶尔用有时记不住 方法一: <div id="test"> test </div> $('#test').mouseover(function () ...

  10. 厉害了,Apache架构师们遵循的 30 条设计原则

    作者:Srinath 翻译:贺卓凡,来源:公众号ImportSource Srinath通过不懈的努力最终总结出了30条架构原则,他主张架构师的角色应该由开发团队本身去扮演,而不是专门有个架构师团队或 ...