AtCoder Grand Contest 001 E - BBQ Hard 数学+dp
2017-09-13 19:20
483 查看
题意
n<=200000,1<=ai,bi<=2000
分析
有个小结论就是Cai+ajai+aj+bi+bj等于平面直角坐标系中点(ai,bi)走到点(−aj,−bj)的不同的方案数。证明的话十分显然就不说了。那么我们就可以把所有点扔到平面直角坐标系上,然后直接dp即可。
代码
#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<algorithm> using namespace std; typedef long long LL; const int N=200005; const int MOD=1000000007; int n,a ,b ,jc[8005],ny[8005]; LL f[4005][4005]; int read() { int x=0,f=1;char ch=getchar(); while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int ksm(int x,int y) { int ans=1; while (y) { if (y&1) ans=(LL)ans*x%MOD; x=(LL)x*x%MOD;y>>=1; } return ans; } int main() { n=read();int mx=0; for (int i=1;i<=n;i++) a[i]=read(),b[i]=read(),mx=max(mx,max(a[i],b[i])); for (int i=1;i<=n;i++) f[a[i]+mx][b[i]+mx]++; jc[0]=ny[0]=1; for (int i=1;i<=mx*4;i++) jc[i]=(LL)jc[i-1]*i%MOD,ny[i]=ksm(jc[i],MOD-2); LL ans=0; for (int i=mx*2;i>=0;i--) for (int j=mx*2;j>=0;j--) (f[i][j]+=f[i+1][j]+f[i][j+1])%=MOD; for (int i=1;i<=n;i++) (ans+=f[mx-a[i]][mx-b[i]])%=MOD; for (int i=1;i<=n;i++) (ans-=(LL)jc[a[i]*2+b[i]*2]*ny[a[i]*2]%MOD*ny[b[i]*2])%=MOD; ans=ans*ksm(2,MOD-2)%MOD; printf("%lld",(ans+MOD)%MOD); return 0; }
相关文章推荐
- AtCoder Grand Contest 001 E - BBQ Hard
- AtCoder Grand Contest 001 E BBQ Hard
- 【树形DP】[AtCoder Petrozavodsk Contest 001 E] Antennas on Tree
- AtCoder Grand Contest 006 D - Median Pyramid Hard 二分答案
- AtCoder Grand Contest 012 B - Splatter Painting(dp)
- AtCoder Grand Contest 001 F permutation
- (dp)AtCoder Grand Contest 019 D - Shift and Flip
- AtCoder Grand Contest 001 B - Mysterious Light
- AtCoder Grand Contest 001 C - Shorten Diameter
- 【AtCoder3913】【Peterzavodsk Contest 001 F】XOR Tree(状压DP)
- AtCoder Grand Contest 015 E - Mr.Aoki Incubator dp
- (组合数学)AtCoder Grand Contest 019 F - Yes or No
- AtCoder Grand Contest 019 C - Fountain Walk 贪心+dp
- 【AtCoder】(AtCoder Grand Contest 006)D - Median Pyramid Hard
- AtCoder Grand Contest 017 F - Zigzag 状压dp
- 【AtCoder Grand Contest 001 F】【JZOJ 5405】 Permutation
- AtCoder Grand Contest 019 F - Yes or No 数学
- AtCoder Grand Contest 022C: Remainder Game 题解
- (技巧)AtCoder Grand Contest 018 C : Coins
- (组合计数)AtCoder Grand Contest 018 E - Sightseeing Plan