ATcoder 1983 BBQ Hard
E - BBQ Hard
Time limit : 2sec / Memory limit : 256MB
Score : 1400 points
Problem Statement
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
Input
The input is given from Standard Input in the following format:
N
A1 B1
A2 B2
:
AN BN
Output
Print the number of the different ways Snuke can make a serving of Skewer Meal, modulo 109+7.
Sample Input 1
3
1 1
1 1
2 1
Sample Output 1
26
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.

我们可以先强行把 有序对转化成无序对并可以自己加自己的形式,也就是题目要求的 Σ(i=1 to n)Σ(j=i+1 to n) C(a[i]+a[j]+b[i]+b[j] , a[i]+a[j])=[ Σ(i=1 to n)Σ(j=1 to n) C(a[i]+a[j]+b[i]+b[j] , a[i]+a[j]) - Σ(i= 1 to n) C(a[i]*2+b[i]*2 , a[i]*2) ]/2。
后面那个Σ好求,直接带一遍组合数就行了,所以现在问题的关键是Σ(i=1 to n)Σ(j=1 to n) C(a[i]+a[j]+b[i]+b[j] , a[i]+a[j]) 怎么求。
考虑到a[],b[]都是<=2000的,可以从这里入手。我们发现,设点X[i] = {-a[i] , -b[i]} ,Y[i] = {a[i] , b[i]} ,那么上式的含义就是在二维平面上,每次只能向右或者向上走,从每个X[i] 走到每个Y[j]的方案数的和,而这个玩意又很好dp,嗯。。。
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int ha=1000000007;
const int maxn=4005;
const int N=200005,inv=ha/2+1;
int n,px[N],py[N],jc[maxn<<1];
int ans=0,f[maxn][maxn],ni[maxn<<1]; inline int add(int x,int y){
x+=y;
return x>=ha?x-ha:x;
} inline int ksm(int x,int y){
int an=1;
for(;y;y>>=1,x=x*(ll)x%ha) if(y&1) an=an*(ll)x%ha;
return an;
} inline void init(){
jc[0]=1;
for(int i=1;i<=8000;i++) jc[i]=jc[i-1]*(ll)i%ha;
ni[8000]=ksm(jc[8000],ha-2);
for(int i=8000;i;i--) ni[i-1]=ni[i]*(ll)i%ha;
} inline void dp(){
for(int i=0;i<=4000;i++)
for(int j=0;j<=4000;j++){
if(i) f[i][j]=add(f[i][j],f[i-1][j]);
if(j) f[i][j]=add(f[i][j],f[i][j-1]);
}
} inline int C(int x,int y){
return jc[x]*(ll)ni[y]%ha*(ll)ni[x-y]%ha;
} inline void calc(){
for(int i=1;i<=n;i++) ans=add(ans,f[2000+px[i]][2000+py[i]]);
for(int i=1;i<=n;i++) ans=add(ans,ha-C((px[i]+py[i])<<1,py[i]<<1));
ans=ans*(ll)inv%ha;
} int main(){
init();
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d%d",px+i,py+i);
f[2000-px[i]][2000-py[i]]++;
}
dp();
calc();
printf("%d\n",ans);
return 0;
}
ATcoder 1983 BBQ Hard的更多相关文章
- 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练习
1. 3721 Smuggling Marbles 大意: 给定$n+1$节点树, $0$为根节点, 初始在一些节点放一个石子, 然后按顺序进行如下操作. 若$0$节点有石子, 则移入盒子 所有石子移 ...
- Atcoder Grand Contest 001E - BBQ Hard(组合意义转化,思维题)
Atcoder 题面传送门 & 洛谷题面传送门 Yet another 思维题-- 注意到此题 \(n\) 数据范围很大,但是 \(a_i,b_i\) 数据范围很小,这能给我们什么启发呢? 观 ...
- 【agc001e】BBQ HARD(动态规划)
[agc001e]BBQ HARD(动态规划) 题面 atcoder 洛谷 题解 这些agc都是写的整场的题解,现在还是把其中一些题目单独拿出来发 这题可以说非常妙了. 我们可以把这个值看做在网格图上 ...
- AtCoder Regular Contest 061
AtCoder Regular Contest 061 C.Many Formulas 题意 给长度不超过\(10\)且由\(0\)到\(9\)数字组成的串S. 可以在两数字间放\(+\)号. 求所有 ...
- AtCoder Grand Contest 001 C Shorten Diameter 树的直径知识
链接:http://agc001.contest.atcoder.jp/tasks/agc001_c 题解(官方): We use the following well-known fact abou ...
- org.eclipse.jdi.TimeoutException:Timeout occurred while waiting for packet 1983.occurred
eclipse 增大junit内存配置 现象:eclipse在junit测试的时候出现如下错误 org.eclipse.jdi.TimeoutException:Timeout occurred wh ...
- AtCoder Regular Contest 082
我都出了F了……结果并没有出E……atcoder让我差4分上橙是啥意思啊…… C - Together 题意:把每个数加1或减1或不变求最大众数. #include<cstdio> #in ...
- AtCoder Regular Contest 069 D
D - Menagerie Time limit : 2sec / Memory limit : 256MB Score : 500 points Problem Statement Snuke, w ...
随机推荐
- Makeflie自动生成依赖,自动化编译
在netbeans里开发,有一个重要文件makefile,是用来编译所有的文件. 项目的目录结构如下,扁平的目录结构,如何实现自动化编译,写makefile呢? 第一版 基础版: CC = g++ C ...
- php-PHP Warning: PHP Startup: Invalid library (maybe not a PHP library) 'xxx.so' in Unknown on line 0
关于xxx.so,今天在安装php的模块时候老是报,xxx.so的问题,虽然不影响使用,但作为一名当年的程序员强迫症患者,誓死要把 他搞清楚,后面发现是删除了也没有影响,因为在安装php的时候已经将他 ...
- Android(java)学习笔记179:多媒体之加载大图片到内存(Bitmap API)
1. Bitmap (API使用) android里面的bitmap中,一个像素点需要4个byte去表示,这是因为android表示颜色是" argb ":其中 a 表示是透明度, ...
- ElasticSearch使用spring-data-elasticSearch的用法
spring-data-Elasticsearch 使用之前,必须先确定版本,elasticsearch 对版本的要求比较高. spring和elasticsearch有两种链接方式,一种是用TCP协 ...
- forward reference extends over definition of value
在scala代码中定义了一个方法,,刚开始直接代码中报错,,后来编译是一直报错,最后只是在sc.stop后边加了一个中括号解决,方法体不能放在main主函数中
- P2756 网络流解决二分图最大匹配
P2756 飞行员配对方案问题 题目背景 第二次世界大战时期.. 题目描述 P2756 飞行员配对方案问题 英国皇家空军从沦陷国征募了大量外籍飞行员.由皇家空军派出的每一架飞机都需要配备在航行技能和语 ...
- 28. TRIGGERS ,29. USER_PRIVILEGES,30. VIEWS
28. TRIGGERS TRIGGERS表提供有关触发器的信息.要查看有关表的触发器的信息,您必须具有该表的TRIGGER权限. TRIGGERS表有以下列: TRIGGER_CATALOG :触发 ...
- python基础知识04-散列类型运算优先级和逻辑运算
散列类型 1.集合 定义集合 se = {1,2,3,4} se = set()定义空集合 se = {1,3,5,7} se2 = {1,3,8,9} se & se2 {1,3} 交集 s ...
- 【C#】【数据结构】006-栈:链栈
C#数据结构:链栈 1.自定义链栈结构: 链栈节点类 using System.Collections; using System.Collections.Generic; using UnityEn ...
- DEV Express
记录在使用DEV Express中遇到的所有问题及解决方案 问题1:将Dev11升级到Dev14 解决方案:将解决方案中原有Dev引用删除,重新添加必须的Dev14引用,问题解决: 问题2:LC.ex ...