题目链接

https://nanti.jisuanke.com/t/19975

题意

Alice 和 Bob 玩游戏 在一个4x4 的方格上 每个人 每次选择2x2的区域 将里面的四个值求和加到最后的分数当中(两个人共用一个分数),然后逆时针翻转他们,Alice 想要分数尽量打 Bob 想要分数尽量小 两个人每次的选择 都是最优的 求最后的分数

思路

玩的次数为 2k k最大为3 数据比较小,想暴力。

我们从后面往前思考

假如我们知道这个棋盘最后一步的状况,那么这时候轮到Bob 选择区域 那么它肯定会选择 和最小的一块区域

那么这个时候 再往上走一步 到 Alice 选择的时候, Alice 肯定会选择 和最大的一块区域 那么 回溯上去 就可以了

然后 只要dfs枚举每一种情况

AC代码

  1. #pragma comment(linker, "/STACK:102400000,102400000")
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <ctype.h>
  5. #include <cstdlib>
  6. #include <cmath>
  7. #include <climits>
  8. #include <ctime>
  9. #include <iostream>
  10. #include <algorithm>
  11. #include <deque>
  12. #include <vector>
  13. #include <queue>
  14. #include <string>
  15. #include <map>
  16. #include <stack>
  17. #include <set>
  18. #include <list>
  19. #include <numeric>
  20. #include <sstream>
  21. #include <iomanip>
  22. #include <limits>
  23. #define pb push_back
  24. #define fi first
  25. #define se second
  26. #define L(on) ((on)<<1)
  27. #define R(on) (L(on) | 1)
  28. #define mkp(a, b) make_pair(a, b)
  29. #define bug puts("***bug***");
  30. #define all(x) x.begin(), x.end()
  31. #define rall(x) x.rbegin(), x.rend()
  32. #define CLR(a, b) memset(a, (b), sizeof(a));
  33. #define syn_close ios::sync_with_stdio(false); cin.tie(0);
  34. #define sp system("pause");
  35. //#define gets gets_s
  36. using namespace std;
  37. typedef long long ll;
  38. typedef long double ld;
  39. typedef long double ld;
  40. typedef unsigned long long ull;
  41. typedef pair <int, int> pii;
  42. typedef pair <ll, ll> pll;
  43. typedef vector <int> vi;
  44. typedef vector <ll> vll;
  45. typedef vector < vi > vvi;
  46. const double PI = acos(-1.0);
  47. const double EI = exp(1.0);
  48. const double eps = 1e-8;
  49. inline int read()
  50. {
  51. char c = getchar(); int ans = 0, vis = 1;
  52. while (c < '0' || c > '9') { if (c == '-') vis = -vis; c = getchar(); }
  53. while (c >= '0' && c <= '9') { ans = ans * 10 + c - '0'; c = getchar(); }
  54. return ans * vis;
  55. }
  56. const int INF = 0x3f3f3f3f;
  57. const ll INFLL = 0x3f3f3f3f3f3f3f3fll;
  58. const int maxn = (int)1e2 + 10;
  59. const int MAXN = (int)1e4 + 10;
  60. const ll MOD = (ll)1e9 + 7;
  61. int k;
  62. int arr[4][4];
  63. void input()
  64. {
  65. k = read();
  66. for (int i = 0; i < 4; i++)
  67. for (int j = 0; j < 4; j++)
  68. arr[i][j] = read();
  69. }
  70. int value(int i, int j)
  71. {
  72. return arr[i][j] + arr[i][j + 1] + arr[i + 1][j] + arr[i + 1][j + 1];
  73. }
  74. int select(int cur, int x, int y)
  75. {
  76. if (cur % 2)
  77. return min(x, y);
  78. return max(x, y);
  79. }
  80. int Index[2][4][2] =
  81. {
  82. 1, 0,
  83. 0, 0,
  84. 1, 1,
  85. 0, 1,
  86. 0, 0,
  87. 0, 1,
  88. 1, 0,
  89. 1, 1,
  90. };
  91. int dfs(int cur)
  92. {
  93. if (cur == 2 * k - 1)
  94. {
  95. int ans = INF;
  96. for (int i = 0; i < 3; i++)
  97. for (int j = 0; j < 3; j++)
  98. ans = min(ans, value(i, j));
  99. return ans;
  100. }
  101. int ans = ((cur & 1) == 1 ? INF : 0);
  102. for (int i = 0; i < 9; i++)
  103. {
  104. int x = i / 3, y = i % 3;
  105. int f[4] = { arr[x][y], arr[x][y + 1], arr[x + 1][y], arr[x + 1][y + 1] };
  106. for (int j = 0; j < 4; j++)
  107. arr[x + Index[0][j][0]][y + Index[0][j][1]] = f[j];
  108. ans = select(cur, ans, value(x, y) + dfs(cur + 1));
  109. for (int j = 0; j < 4; j++)
  110. arr[x + Index[1][j][0]][y + Index[1][j][1]] = f[j];
  111. }
  112. return ans;
  113. }
  114. int main()
  115. {
  116. int t = read();
  117. while (t--)
  118. {
  119. input(); printf("%d\n", dfs(0));
  120. }
  121. }

17南宁区域赛 I - Rake It In 【DFS】的更多相关文章

  1. 高精度乘法-17南宁区域赛F -The Chosen One

    题目大意:给你一个n,然后从1~n隔一个选一个,挑出一个集合然后从集合中继续隔一个挑一个,直到只有一个数,问最后一个数是多少?2<=n<=1050 例如n=5,先选出2,4最后选择4.n= ...

  2. The Maximum Unreachable Node Set 【17南宁区域赛】 【二分匹配】

    题目链接 https://nanti.jisuanke.com/t/19979 题意 给出n个点 m 条边 求选出最大的点数使得这个点集之间 任意两点不可达 题目中给的边是有向边 思路 这道题 实际上 ...

  3. 17 南宁区域赛 F - The Chosen One 【规律】

    题目链接 https://nanti.jisuanke.com/t/19972 题意 给出一个n 然后将 n 个数 标号为 1 -> n 按顺序排列 每次抽掉 奇数位的数 然后求最后剩下那个数字 ...

  4. 17南宁区域赛 J - Rearrangement 【规律】

    题目链接 https://nanti.jisuanke.com/t/19976 题意 给出 一个n 然后 给出 2*n 个数 可以重新排列成两行 然后 相邻的两个数 加起来 不能被三整除 可以上下相邻 ...

  5. 2014年亚洲区域赛北京赛区现场赛A,D,H,I,K题解(hdu5112,5115,5119,5220,5122)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud 下午在HDU上打了一下今年北京区域赛的重现,过了5题,看来单挑只能拿拿铜牌,呜呜. ...

  6. HDU5558 Alice's Classified Message(合肥区域赛 后缀数组)

    当初合肥区域赛的题(现场赛改了数据范围就暴力过了),可惜当初后缀数组算法的名字都没听过,现在重做下. i从1到n - 1,每次枚举rank[i]附近的排名,并记录当起点小于i时的LCP(rank[i] ...

  7. 36th成都区域赛网络赛 hdoj4039 The Social Network(建图+字符串处理)

    这题是某年成都区域赛网络赛的一题. 这题思路非常easy,可是从时间上考虑,不妨不要用矩阵存储,我用的链式前向星. 採用线上查询.利用map对字符串编号,由于非常方便.要推荐的朋友,事实上就是朋友的朋 ...

  8. 【2013南京区域赛】部分题解 hdu4802—4812

    上周末打了一场训练赛,题目是13年南京区域赛的 这场题目有好几个本来应该是我擅长的,但是可能是太久没做比赛了各种小错误代码写的也丑各种warusn trush搞得人很不爽 全场题之一的1002也没有想 ...

  9. hdu5080:几何+polya计数(鞍山区域赛K题)

    /* 鞍山区域赛的K题..当时比赛都没来得及看(反正看了也不会) 学了polya定理之后就赶紧跑来补这个题.. 由于几何比较烂写了又丑又长的代码,还debug了很久.. 比较感动的是竟然1Y了.. * ...

随机推荐

  1. undefined reference to `shm_unlink'

    1.问题描述: 在编译一个程序的时候提示这样的错误: BLog.cpp:(.text+0x5fc): undefined reference to `shm_unlink'DBLog.cpp:(.te ...

  2. python 转化文件编码 utf8

    使用visual studio最大的一个问题就是文件编码问题,当文件中有中文时,visual studio 会默认为区域编码,也就是gb2312,如果想跨平台或者不用vs编译的话,就会因为编码问题导致 ...

  3. 基于C#的超市收银管理系统

    基于C#的超市收银管理系统 前序 一直在忙学习Qt有关的知识,非常有幸这学期学习了C#.让我也感觉到了一丝欣慰,欣慰的是感觉好上手啊,学了几天顿时懂了.好多控件的使用方法好类似,尽管平时上课没有怎么认 ...

  4. mysql 1005 错误

    建立外键的时候两个 表的相对应的 类型不一致!

  5. TLS,SSL,HTTPS with Python(转)

    From: 扫盲 HTTPS 和 SSL/TLS 协议[0]:引子 需要了解的背景知识: 术语 HTTPS,SSL,TLS 长连接与短连接的关系 了解 CA 证书 基本流程 一.术语扫盲 1.什么是S ...

  6. Eclipse 悬浮提示

    Eclipse 悬浮提示 使用悬浮提示 java 编辑器中包含了不同类型的悬浮提示,悬浮提示提供了鼠标指针指向元素的额外信息.所有java编辑器中相关的悬浮提示可以通过 preference(首选项) ...

  7. 012android初级篇之Handler机制

    设计Handler类的目的 Handler类被用来注册到一个线程中,这样可以提供一个简单的通信渠道,用来发送数据到这个线程. 可作为UI线程与后台线程交互的几种方法之一. 具体用途 消息的分发和处理, ...

  8. POI Excel 冷冻线

    冷冻线 Sheet.createFreezePane data bar and  color scale SheetConditionalFormatting scf = sheet.getSheet ...

  9. MathType可以编辑省略号吗

    说到省略号大家可能会想到写文章的时候会用到,其实在数学中也会常常的使用到.当数学过程是重复有规律性的过程时,就会用到它.MathType是一款数学公式编辑器,那么,在数学公式中,MathType编辑时 ...

  10. iOS-毛玻璃、navigationBar滑动颜色渐变

    1.毛玻璃实现 iOS8以上,官方提供了系统方法实现毛玻璃,代码如下: // iOS8 UIVisualEffectView UIImageView *bgView = [[UIImageView a ...