题意

题目链接

Sol

非常妙的一道题目。

首先,我们可以把\(C_{a_i + b_i + a_j + b_j}^{a_i + a_j}\)看做从\((-a_i, -b_i)\)走到\((a_j, b_j)\)的方案数

然后全都放的一起dp,\(f[i][j]\)表示从\((i, j)\)之前的所有点到\((i, j)\)的方案数

减去重复的即可


  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int MAXN = 2e5 + 10, mod = 1e9 + 7;
  4. inline int read() {
  5. int x = 0, f = 1; char c = getchar();
  6. while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
  7. while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  8. return x * f;
  9. }
  10. int N, a[MAXN], b[MAXN], f[5001][5001], fac[10001], ifac[10001];
  11. int add(int x, int y) {
  12. if(x + y < 0) return x + y + mod;
  13. return x + y > mod ? x + y - mod : x + y ;
  14. }
  15. int mul(int x, int y) {
  16. return 1ll * x * y % mod;
  17. }
  18. int fastpow(int a, int p) {
  19. int base = 1;
  20. while(p) {
  21. if(p & 1) base = mul(base, a);
  22. a = mul(a, a); p >>= 1;
  23. }
  24. return base;
  25. }
  26. void init() {
  27. fac[0] = 1;
  28. for(int i = 1; i <= 8000; i++) fac[i] = mul(i, fac[i - 1]);
  29. ifac[8000] = fastpow(fac[8000], mod - 2);
  30. for(int i = 8000; i; i--) ifac[i - 1] = mul(i, ifac[i]);
  31. }
  32. int id(int x) {
  33. return 2001 + x;
  34. }
  35. int C(int N, int M) {
  36. return 1ll * fac[N] * ifac[N - M] % mod * ifac[M] % mod;
  37. }
  38. main() {
  39. // freopen("a.in", "r", stdin);
  40. init();
  41. N = read();
  42. for(int i = 1; i <= N; i++) a[i] = read(), b[i] = read(), f[id(-a[i])][id(-b[i])]++;
  43. for(int i = 1; i <= 4221; i++)
  44. for(int j = 1; j <= 4221; j++)
  45. f[i][j] = add(f[i][j], add(f[i - 1][j], f[i][j - 1]));
  46. // printf("%d %d %d\n", i, j, f[i][j]);
  47. int sum = 0;
  48. for(int i = 1; i <= N; i++)
  49. sum = add(sum, add(f[id(a[i])][id(b[i])], -C(a[i] + b[i] + a[i] + b[i], a[i] + a[i])));
  50. //这里会到8000.。。
  51. sum = 1ll * sum * 500000004ll % mod;
  52. cout << sum % mod;
  53. return 0;
  54. }
  55. /*
  56. 8
  57. 2000 2000
  58. 1999 1998
  59. 1 1
  60. 1 1
  61. 2 1
  62. 1 3
  63. 2 1
  64. 3 3
  65. */

agc001E - BBQ Hard(dp 组合数)的更多相关文章

  1. 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 ...

  2. [Agc001E] BBQ Hard

    [Agc001E] BBQ Hard 题目大意 给定\(n\)对正整数\(a_i,b_i\),求\(\sum_{i=1}^{n-1} \sum_{j=i+1}^n \binom{a_i+b_i+a_j ...

  3. noj 2033 一页书的书 [ dp + 组合数 ]

    传送门 一页书的书 时间限制(普通/Java) : 1000 MS/ 3000 MS          运行内存限制 : 65536 KByte总提交 : 53            测试通过 : 1 ...

  4. 【区间dp+组合数+数学期望】Expression

    https://www.bnuoj.com/v3/contest_show.php?cid=9148#problem/I [题意] 给定n个操作数和n-1个操作符,组成一个数学式子.每次可以选择两个相 ...

  5. [agc001E]BBQ Hard[组合数性质+dp]

    Description 传送门 Solution 题目简化后要求的实际上是$\sum _{i=1}^{n-1}\sum _{j=i+1}^{n}C^{A[i]+A[j]}_{A[i]+A[j]+B[i ...

  6. hdu 3944 DP? 组合数取模(Lucas定理+预处理+帕斯卡公式优化)

    DP? Problem Description Figure 1 shows the Yang Hui Triangle. We number the row from top to bottom 0 ...

  7. Contest 20140708 testB dp 组合数

    testB 输入文件: testB.in  输出文件testB.out 时限3000ms 问题描述: 定义这样一个序列(a1,b1),(a2,b2),…,(ak,bk)如果这个序列是方序列的话必须满足 ...

  8. HDU 5396 Expression(DP+组合数)(详解)

    题目大意: 给你一个n然后是n个数. 然后是n-1个操作符,操作符是插入在两个数字之间的. 由于你不同的运算顺序,会产生不同的结果. 比如: 1 + 1 * 2 有两种  (1+1)*2   或者   ...

  9. LightOJ - 1246 Colorful Board(DP+组合数)

    http://lightoj.com/volume_showproblem.php?problem=1246 题意 有个(M+1)*(N+1)的棋盘,用k种颜色给它涂色,要求曼哈顿距离为奇数的格子之间 ...

随机推荐

  1. hdu1403(后缀数组模板)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1403 题意: 给出两个字符串, 求他们的最长公共子串 思路: 两个字符串的最长公共子串长度显然就是两个 ...

  2. jmeter - 录制web网页

    1.       打开JMeter工具 创建一个线程组(右键点击“测试计划”--->“添加”---->“线程组”) 创建一个http代理服务器(右键点击“工作台”--->“添加”-- ...

  3. Spark大数据处理 之 从WordCount看Spark大数据处理的核心机制(2)

    在上一篇文章中,我们讲了Spark大数据处理的可扩展性和负载均衡,今天要讲的是更为重点的容错处理,这涉及到Spark的应用场景和RDD的设计来源. Spark的应用场景 Spark主要针对两种场景: ...

  4. Orcale创建函数(function)

    Oraclec创建函数的语法规则 create or replace function  函数名 (参数名1 参数类型,参数名2 参数类型)  return number  is Result num ...

  5. luogu1210 回文检测

    Manacher 正确读法:抹内A撤(马拉车) (跟着假硕学英语) 我们把原来的字符串,通过玄学处理,变成只留下字母,且每两个字母之间有一个奇怪的字符的那种Manacher专用字符串. 建立双射关系f ...

  6. EM最大期望算法

    [简介] em算法,指的是最大期望算法(Expectation Maximization Algorithm,又译期望最大化算法),是一种迭代算法,在统计学中被用于寻找,依赖于不可观察的隐性变量的概率 ...

  7. spring boot 1.4.2.RELEASE+Thymeleaf+mybatis 集成通用maper,与分页插件:

    <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot ...

  8. import与from...import...的区别

    from ... import ... 的用法和直接import的区别: 1.直接使用import时,如果需要使用到导入模块内的属性和方法,必须使用模块名.属性和模块名.方法的方式进行调用 2.使用f ...

  9. CodeForces - 359C-Prime Number

    Simon has a prime number x and an array of non-negative integers a1, a2, ..., an. Simon loves fracti ...

  10. 南昌大学航天杯第二届程序设计竞赛校赛网络同步赛 I

    链接:https://www.nowcoder.com/acm/contest/122/I来源:牛客网 题目描述 小q最近在做一个项目,其中涉及到了一个计时器的使用,但是笨笨的小q却犯难了,他想请你帮 ...