题目

分析

发现,\(C_{ai+aj+bi+bj}^{ai+aj}\),其实就等于从(0,0)走最短路到(ai+aj,bi+bj)。

我们可以想办法将i、j分开,从(0,0)走最短路到(ai+aj,bi+bj)其实就相当于从(-ai,-bi)走最短路到(aj,bj),

那么,在坐标系上,计算出所有(-ai,-bi),到所有(ai,bi)的值,

但是对于i—>i会被算上,减去这种情况;

又因为i—>j会算两次,再除一个2,就是答案。

#include <cmath>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
const int maxlongint=2147483647;
const long long mo=1e9+7;
const int N=4010;
const int M=2002;
using namespace std;
long long f[N][N],jc[N*2],n,m,ans,ny[N*2],bz[N][N];
long long mi(long long x,long long y)
{
long long sum=1;
while(y)
{
if(y&1) sum=sum*x%mo;
x=x*x%mo;
y>>=1;
}
return sum;
}
long long C(int m,int n)
{
return jc[m]*ny[n]%mo*ny[m-n]%mo;
}
int main()
{
jc[0]=ny[0]=1;
for(int i=1;i<=N*2-1;i++) jc[i]=jc[i-1]*i%mo,ny[i]=mi(jc[i],mo-2);
scanf("%lld",&n);
ans=0;
for(int i=1,x,y;i<=n;i++)
{
scanf("%d%d",&x,&y);
bz[M+x][M+y]++;
f[M-x][M-y]++;
ans=(ans-C(x+y+x+y,x+x)+mo)%mo;
}
for(int i=1;i<=N-1;i++)
for(int j=1;j<=N-1;j++)
f[i][j]=(f[i][j]+f[i][j-1]+f[i-1][j])%mo,ans=(ans+bz[i][j]*f[i][j]%mo)%mo;
printf("%lld",ans*ny[2]%mo);
}

JZOJ5358【NOIP2017提高A组模拟9.12】BBQ的更多相关文章

  1. 【NOIP2017提高A组模拟9.12】Arrays and Palindrome

    [NOIP2017提高A组模拟9.12]Arrays and Palindrome[SPJ] 题目 Description Input Output Sample Input 1 6 Sample O ...

  2. 【NOIP2017提高A组模拟9.17】猫

    [NOIP2017提高A组模拟9.17]猫 题目 Description 信息组最近猫成灾了! 隔壁物理组也拿猫没办法. 信息组组长只好去请神刀手来帮他们消灭猫.信息组现在共有n 只猫(n 为正整数) ...

  3. 【NOIP2017提高A组模拟9.17】组合数问题

    [NOIP2017提高A组模拟9.17]组合数问题 题目 Description 定义"组合数"S(n,m)代表将n 个不同的元素拆分成m 个非空集合的方案数. 举个例子,将{1,2,3}拆分成2 个 ...

  4. JZOJ 100029. 【NOIP2017提高A组模拟7.8】陪审团

    100029. [NOIP2017提高A组模拟7.8]陪审团 Time Limits: 1000 ms  Memory Limits: 131072 KB  Detailed Limits   Got ...

  5. JZOJ 5328. 【NOIP2017提高A组模拟8.22】世界线

    5328. [NOIP2017提高A组模拟8.22]世界线 (File IO): input:worldline.in output:worldline.out Time Limits: 1500 m ...

  6. JZOJ 5329. 【NOIP2017提高A组模拟8.22】时间机器

    5329. [NOIP2017提高A组模拟8.22]时间机器 (File IO): input:machine.in output:machine.out Time Limits: 2000 ms M ...

  7. JZOJ 5307. 【NOIP2017提高A组模拟8.18】偷窃 (Standard IO)

    5307. [NOIP2017提高A组模拟8.18]偷窃 (Standard IO) Time Limits: 1000 ms Memory Limits: 262144 KB Description ...

  8. JZOJ 5286. 【NOIP2017提高A组模拟8.16】花花的森林 (Standard IO)

    5286. [NOIP2017提高A组模拟8.16]花花的森林 (Standard IO) Time Limits: 1000 ms Memory Limits: 131072 KB Descript ...

  9. JZOJ 5305. 【NOIP2017提高A组模拟8.18】C (Standard IO)

    5305. [NOIP2017提高A组模拟8.18]C (Standard IO) Time Limits: 1000 ms Memory Limits: 131072 KB Description ...

随机推荐

  1. 【机器学习】深入理解拉格朗日乘子法(Lagrange Multiplier) 和KKT条件

    在求取有约束条件的优化问题时,拉格朗日乘子法(Lagrange Multiplier) 和KKT条件是非常重要的两个求取方法,对于等式约束的优化问题,可以应用拉格朗日乘子法去求取最优值:如果含有不等式 ...

  2. gzip 命令

    NAME gzip -- compression/decompression tool using Lempel-Ziv coding (LZ77) SYNOPSIS gzip [-cdfhkLlNn ...

  3. mysql拆分逗号一列变多行

    需求: SELECT ), ) FROM TABLE a INNER JOIN mysql.help_topic b )

  4. Ubuntu - Ubuntu应用记录(1)

    1.发生dpkg status database is locked by another process 原因是包管理器没有正确关闭.需要重启计算机或者重新打开终端 输入: sudo rm /var ...

  5. Luogu P5221 Product

    题目 注意一下空间限制. 令\(f(n)=\prod\limits_{i=1}^n\prod\limits_{j=1}^nij,g(n)=\prod\limits_{i=1}^n\prod\limit ...

  6. Linux-1.3目录结构,基础命令

    1.Linux目录结构 2.Linux基础命令(常用) ctrl+alt+T(打开终端) cd 切换文件夹(pwd查看当前目录) cd /home 绝对路径 以根目录开头 cd admin 相对路径 ...

  7. TCP socket 编程

    TCP socket 编程 讲一下 socket 编程 步骤 使用 socket 模块 建立 TCP socket 客户端和服务端 客户端和服务端之间的通信 图解 编程 举个例子 tcp_server ...

  8. 113、stack的优势 (Swarm20)

    参考https://www.cnblogs.com/CloudMan6/p/8157391.html   stack 将应用所包含的service,依赖的secret volume 等资源,以及他们之 ...

  9. MySql查询进阶

    1.1 as关键字 用于 给显示结果中字段 或者 表 起别名 select 别名.字段名 from 表名 as 别名 where 条件语句 # 对字段起别名 select id as '编号', na ...

  10. 浅尝https

    HTTPS http超文本传输协议,所以的东西都是明文传输,容易被拦截,被攻击,我们希望能对通话内容进行加密,那么因此而生,出现了https https:在http的基础上新增加了SSL层 先放图 / ...