题面

洛谷

题解

代码

\(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. PhoneGap 白名单安全机制 navigator.app 加载外部页面返回以及退出介绍

    一. Phonegap 白名单安全机制 Phonegap应用的页面大多存在于本地,但有时需要加载外部的Web页面到应用内置的浏览器 视图中已完成特定的应用功能,出于安全性考虑,PhoneGap 设立了 ...

  2. GPU性能:光栅化、图层混合、离屏渲染

    So, shouldRasterize will not affect the green/red you see using Instruments. In order to have everyt ...

  3. iOS的图片:解码(CPU)与内存(缓存)

    图片的数据:资源数据(地址).原始数据(Data).显示数据(解码后的数据) 解压图片 - PNG或者JPEG压缩之后的图片文件会比同质量的位图小得多.但是在图片绘制到屏幕上之前,必须把它扩展成完整的 ...

  4. 【vue】todolist小练习

    参考链接: http://www.imooc.com/learn/694 http://www.cnblogs.com/Chen-XiaoJun/p/6238137.html http://blog. ...

  5. Tomcat中Pipeline

    Pipeline 节选部分源码.源码版本 Tomcat8.5 处理模式 Pipeline--Valve是一种责任链模式,它和普通责任链模式有两点区别: 每个Pipeline都是有特定的Valve,而且 ...

  6. ActiveRecord初始化,可以实现jfinal系统启动完成后,再建立数据库连接

    1.JFinalConfig的afterJFinalStart方法,可以实现系统启动成功后,调用的方法 2.ActiveRecord 多数据源初始化 package com.meiah.common; ...

  7. nRF5 SDK for Mesh(六) BLE MESH 的 基础概念

    Basic Bluetooth Mesh concepts The Bluetooth Mesh is a profile specification developed and published ...

  8. ubuntu 14.04 将窗体button移到右边

    刚刚安装了Ubuntu 14.04,想改动窗体button的位置.但依照曾经的办法发现不行了,在gconftool-->apps中找不到metacity. 多方查找后找到解决方式,例如以下 Ub ...

  9. C# 参数关键字params的作用

    为了将方法声明为可以接受可变数量参数的方法,我们可以使用params关键字来声明数组,要求: (1)在方法声明中的 params 关键字之后不允许任何其他参数,并且在方法声明中只允许一个 params ...

  10. JNDI数据源(在Tomcat下配置JNDI多数据源实例)

    一,添加数据库驱动包加入classpath. 这里我用到了oracle和mysql.所以由两个jar包:ojdbc14.jar和mysql-connector-java-5.1.13-bin.jar. ...