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 ...
随机推荐
- java nio 读取大文件
package com.yao.bigfile; import java.io.File; import java.io.IOException; import java.io.RandomAcces ...
- Python3简明教程(十二)—— 模块
在这节我们将要学习 Python 模块相关知识.包括模块的概念和导入方法,包的概念和使用,第三方模块的介绍,命令行参数的使用等. 模块 到目前为止,我们在 Python 解释器中写的所有代码都在我们退 ...
- python读取绝对路径的三种方式
import pandas as pd dood_inf0=pd.read_csv("C:\\Users\\Administrator\\Desktop\\food_info.csv&quo ...
- Android N requires the IDE to be running with Java 1.8 or later
Android Studio需要两个JDK: ide jdk和project jdk: 前者是IDE本身运行使用的JDK. 后者用于编译Java代码 Project JDK 可以通过file-&g ...
- Caused by: java.lang.IllegalArgumentException: Parameter Maps collection does not contain value for com.bj186.crm.pojo.User
原因分析: myBatis在写delete语句的时候,多写了一个属性 错误的代码: <delete id="deleteUser" parameterType="I ...
- HDU4300 Clairewd’s message(拓展kmp)
Problem Description Clairewd is a member of FBI. After several years concealing in BUPT, she interce ...
- Shell数值比较
Shell数值比较 比较 描述 n1 -eq n2 检查n1是否与n2相等 n1 -ge n2 检查n1是否大于或等于n2 n1 -gt n2 检查n1是否大于n2 n1 -le n2 检查n1是否小 ...
- bzoj 1051 受欢迎的牛-tarjan
https://www.lydsy.com/JudgeOnline/problem.php?id=1051 如果A喜欢B,那么A->B连边,那么整个图储存下来,如果有好多个牛是受欢迎的,那么他们 ...
- java反编译工具jad
下好以后解压就可以用了,软件就只有一个exe文件和一个帮助文件.在众多的JAVA反编译工具中,有几种非常著名的工具使用了相同的核心引擎——JAD,其中主要包括:FrontEnd Plus.mDeJav ...
- API对接中经常会出现的签名获取,这只是某一种,仅供给有需要的人参考
要求: 1.对所有传入参数(含系统参数和接口参数)按照字段名的 ASCII 码从小到大排序(字典序)后,使用 URL 键值对的格式.(即 key1=value1&key2=value2…)拼接 ...