题面

洛谷

题解

代码

\(50pts\)

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstdlib>
  4. #include<cstring>
  5. #include<cmath>
  6. #include<algorithm>
  7. using namespace std;
  8. inline int gi() {
  9. register int data = 0, w = 1;
  10. register char ch = 0;
  11. while (ch != '-' && (ch > '9' || ch < '0')) ch = getchar();
  12. if (ch == '-') w = -1 , ch = getchar();
  13. while (ch >= '0' && ch <= '9') data = data * 10 + (ch ^ 48), ch = getchar();
  14. return w * data;
  15. }
  16. int N, go[20];
  17. int a[20][20];
  18. int s[20]; //当前x队获得了多少分
  19. int ans = 0;
  20. int tot = 0;
  21. int score = 0;
  22. void dfs(int x, int y) { //刷到了表的第x行,第y列
  23. if (score > tot) return ;
  24. if (x == N + 1) {
  25. bool F = 1;
  26. for (int i = 1; i <= N; i++)
  27. if (s[i] != go[i]) {
  28. F = 0; break;
  29. }
  30. ans += F;
  31. if (ans == 1000000007) ans = 0;
  32. } else {
  33. //这一盘输了
  34. score += 3;
  35. s[y] += 3;
  36. if (s[y] > go[y]) goto nxt1;
  37. if (s[x] > go[x]) {
  38. score -= 3;
  39. s[y] -= 3;
  40. return ;
  41. }
  42. if (s[x] + 3 * (N - y) < go[x]) goto nxt1;
  43. if (s[y] + 3 * (N - x) < go[y]) {
  44. score -= 3;
  45. s[y] -= 3;
  46. return ;
  47. }
  48. if (y == x - 1) dfs(x + 1, 1);
  49. else dfs(x, y + 1);
  50. nxt1 : { }
  51. score -= 3;
  52. s[y] -= 3;
  53. //这一盘赢了
  54. score += 3;
  55. s[x] += 3;
  56. if (s[x] > go[x]) goto nxt2;
  57. if (s[y] > go[y]) {
  58. s[x] -= 3;
  59. score -= 3;
  60. return ;
  61. }
  62. if (s[y] + 3 * (N - x) < go[y]) goto nxt2;
  63. if (s[x] + 3 * (N - y) < go[x]) {
  64. s[x] -= 3;
  65. score -= 3;
  66. return ;
  67. }
  68. if (y == x - 1) dfs(x + 1, 1);
  69. else dfs(x, y + 1);
  70. nxt2 : { }
  71. s[x] -= 3;
  72. score -= 3;
  73. //这一盘和了
  74. score += 2;
  75. s[x]++, s[y]++;
  76. if (s[x] > go[x] || s[y] > go[y]) {
  77. score -= 2;
  78. s[x]--, s[y]--;
  79. return ;
  80. }
  81. if (s[y] + 3 * (N - x) < go[y]) {
  82. s[x]--, s[y]--;
  83. score -= 2;
  84. return ;
  85. }
  86. if (s[x] + 3 * (N - y) < go[x]) {
  87. s[x]--, s[y]--;
  88. score -= 2;
  89. return ;
  90. }
  91. if (y == x - 1) dfs(x + 1, 1);
  92. else dfs(x, y + 1);
  93. s[x]--, s[y]--;
  94. score -= 2;
  95. }
  96. }
  97. int main () {
  98. N = gi();
  99. for (int i = 1; i <= N; i++) tot += go[i] = gi();
  100. dfs(2, 1);
  101. printf("%d\n", ans);
  102. return 0;
  103. }

\(100pts\)

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstdlib>
  4. #include<cstring>
  5. #include<cmath>
  6. #include<algorithm>
  7. #include<map>
  8. using namespace std;
  9. typedef unsigned long long ull;
  10. #define Mod 1000000007
  11. inline void add(int &x, int y) { x += y; if (x >= Mod) x -= Mod; }
  12. int N, a[20], tmp[20];
  13. map<ull, int> mp;
  14. int dfs(int x, int y) {
  15. if (a[x] > (x - y) * 3) return 0;
  16. int res = 0; ull hs = 0;
  17. if (x == y) {
  18. if (x == 1) return 1;
  19. for (int i = 1; i < x; i++) tmp[i] = a[i];
  20. hs = x - 1; sort(&tmp[1], &tmp[x]);
  21. for (int i = 1; i < x; i++) hs = 27 * hs + tmp[i];
  22. return mp.find(hs) != mp.end() ? mp[hs] : mp[hs] = dfs(x - 1, 1);
  23. }
  24. if (a[x] >= 3) a[x] -= 3, add(res, dfs(x, y + 1)), a[x] += 3;
  25. if (a[x] && a[y]) --a[x], --a[y], add(res, dfs(x, y + 1)), ++a[x], ++a[y];
  26. if (a[y] >= 3) a[y] -= 3, add(res, dfs(x, y + 1)), a[y] += 3;
  27. return res;
  28. }
  29. int main () {
  30. cin >> N;
  31. for (int i = 1; i <= N; i++) cin >> a[i];
  32. sort(&a[1], &a[N + 1], greater<int>());
  33. printf("%d\n", dfs(N, 1));
  34. return 0;
  35. }

【LG3230】[HNOI2013]比赛的更多相关文章

  1. 【BZOJ3139】[HNOI2013]比赛(搜索)

    [BZOJ3139][HNOI2013]比赛(搜索) 题面 BZOJ 洛谷 题解 双倍经验

  2. [HNOI2013]比赛 (用Hash实现记忆化搜索)

    [HNOI2013]比赛 题目描述 沫沫非常喜欢看足球赛,但因为沉迷于射箭游戏,错过了最近的一次足球联赛.此次联 赛共N支球队参加,比赛规则如下: (1) 每两支球队之间踢一场比赛. (2) 若平局, ...

  3. [HNOI2013]比赛 搜索

    [HNOI2013]比赛 搜索. LG传送门 直接暴力有60,考场上写的60,结果挂成40. 考虑在暴力的同时加个记忆化,把剩下的球队数和每支球队的得分情况hash一下,每次搜到还剩\(t\)个队的时 ...

  4. [BZOJ3139][HNOI2013]比赛(搜索)

    3139: [Hnoi2013]比赛 Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 1439  Solved: 719[Submit][Status] ...

  5. 【题解】HNOI2013比赛

    [题解][P3230 HNOI2013]比赛 将得分的序列化成样例给的那种表格,发现一行和一列是同时确定的.这个表格之前是正方形的,后来长宽都减去一,还是正方形.问题形式是递归的.这就启示我们可以把这 ...

  6. BZOJ1306 [CQOI2009]match循环赛/BZOJ3139 [Hnoi2013]比赛[dfs剪枝+细节题]

    地址 看数据范围很明显的搜索题,暴力dfs是枚举按顺序每一场比赛的胜败情况到底,合法就累计.$O(3^{n*(n-1)/2})$.n到10的时候比较大,考虑剪枝. 本人比较菜所以关键性的剪枝没想出来, ...

  7. [BZOJ3139][HNOI2013] 比赛

    Description 沫沫非常喜欢看足球赛,但因为沉迷于射箭游戏,错过了最近的一次足球联赛.此次联 赛共N支球队参加,比赛规则如下:  (1) 每两支球队之间踢一场比赛. (2) 若平局,两支球队各 ...

  8. 3139:[HNOI2013]比赛 - BZOJ

    题目描述 Description 沫沫非常喜欢看足球赛,但因为沉迷于射箭游戏,错过了最近的一次足球联赛.此次联赛共N只队伍参加,比赛规则如下: (1) 每两支球队之间踢一场比赛. (2) 若平局,两支 ...

  9. bzoj 3139: [Hnoi2013]比赛

    Description 沫沫非常喜欢看足球赛,但因为沉迷于射箭游戏,错过了最近的一次足球联赛.此次联 赛共N支球队参加,比赛规则如下: (1) 每两支球队之间踢一场比赛. (2) 若平局,两支球队各得 ...

随机推荐

  1. 发送邮件 html格式

    下面黄色代码为实现发送邮件 FileStream fs = new FileStream(Server.MapPath("../ImportUserIOExcel/productConsul ...

  2. XCODE7 和IOS9适配后的一些问题

    网上比较常规的几个问题就不细说了. 什么HTTPS.bitcode.什么什么的. 记录几个自己又遇到了但是网上没有说的. 启动应用报错, *** Terminating app due to unca ...

  3. PAT——1052. 卖个萌

    萌萌哒表情符号通常由“手”.“眼”.“口”三个主要部分组成.简单起见,我们假设一个表情符号是按下列格式输出的: [左手]([左眼][口][右眼])[右手] 现给出可选用的符号集合,请你按用户的要求输出 ...

  4. [SCOI2005]互不侵犯(状压DP)

    嗝~算是状压DP的经典题了~ #\(\mathcal{\color{red}{Description}}\) 在\(N×N\)的棋盘里面放\(K\)个国王,使他们互不攻击,共有多少种摆放方案.国王能攻 ...

  5. OPENGL绘制文字

    OPENGL没有提供直接绘制文字的功能,需要借助于操作系统. 用OPENGL绘制文字比较常见的方法是利用显示列表.创建一系列显示列表,每个字符对应一个列表编号.例如,'A'对应列表编号1000+'A' ...

  6. 翻译 TI SerialBLEbridge V 1.4.1

    原文地址:http://processors.wiki.ti.com/index.php/SerialBLEbridge_V_1.4.1 Sample App Overview This page d ...

  7. php多进程编程实现与优化

    PHP多进程API 创建子进程 @params void @returns int int pcntl_fork(void) 成功时,在父进程执行线程内返回产生的子进程PID,在子进程执行线程内返回0 ...

  8. Weex 环境搭建 (一)

    1  安装Node.js 去Node.js 官网  https://nodejs.org/      下载安装文件安装. 安装好后,根据如下命令检查是否安装正常. 在windows 环境下,开始-运行 ...

  9. 允许跨域资源共享(CORS)携带 Cookie (转载)

    如何让CORS携带Cookie CORS 是一个 W3C 标准,全称是“跨域资源共享”(Cross-origin resource sharing).默认浏览器为了安全,遵循“同源策略”,不允许 Aj ...

  10. Failed to read artifact descriptor for org.apache.maven.plugins:maven-jar-plugin

    在更新maven项目的时候出现许多jar包找不到的问题,但是在本地仓库中查找的时候包含这些jar包. 解决办法: 把所有报错缺少的jar包所在的文件夹删掉,重新更新maven项目,重新下载完成后错误解 ...