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 ...
随机推荐
- Javaweb学习笔记2—Tomcat和http协议
今天来讲javaweb的第二个阶段学习. 老规矩,首先先用一张思维导图来展现今天的博客内容. ps:我的思维是用的xMind画的,如果你对我的思维导图感兴趣并且想看到你们跟详细的备注信息,请点击下 ...
- [Windows Server 2012] 安装IIS8.5及FTP
★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com ★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频. ★ 本节我们将带领大家:安装IIS ...
- 关于dzzoffice 破解版
最近看到很多人在搜索dzzoffice破解版,其实dzzoffie是一款全开源的产品,开放的功能是与演示站中一摸一样的,所以并不会有人破解这种全开源的系统.那么为什么会有人搜索这样的关键词呢? 可能大 ...
- 11gR2集群件任务角色分离(Job Role Separation)简介
从11gR2版本开始,Oracle推荐使用不同的操作系统用户安装GI和数据库软件,例如:使用grid用户安装GI,使用Oracle用户安装数据库软件.当然,用户还是可以使用Oracle用户安装G ...
- Unity3D——Epirome框架_TimerManager计时任务管理器
1.Timer timer = new Timer(); 创建时间管理器 参数(float time, TimeUnit timeUnit,bool ignoreTimeScale = false, ...
- 命令终端执行python
windows进入cmd 1.进入cmd窗口,找到存放py文件的地址(如E:\learn_mock) 2.退出python,输入exit() linux下一样
- 2018 CCPC 女生赛 hdoj6288 缺失的数据范围
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=6288 Summarize:1.二分查找答案: 2.自带log函数精度不够,需自己写: 3.注意二分递归 ...
- 浅谈stiring数
在组合数学,Stirling数可指两类数,第一类Stirling数和第二类Stirling数. stirling常应用于许多组合枚举问题中. 第一类stirling数: 对第一类Stirling数 ...
- 【转载】form表单的两种提交方式,submit和button的用法
1.当输入用户名和密码为空的时候,需要判断.这时候就用到了校验用户名和密码,这个需要在jsp的前端页面写:有两种方法,一种是用submit提交.一种是用button提交.方法一: 在jsp的前端页面的 ...
- float 和 clear
float 特性1:可以为行内浮动元素设置宽高 <!DOCTYPE html> <html> <head> <meta charset="UTF-8 ...