17南宁区域赛 I - Rake It In 【DFS】
题目链接
https://nanti.jisuanke.com/t/19975
题意
Alice 和 Bob 玩游戏 在一个4x4 的方格上 每个人 每次选择2x2的区域 将里面的四个值求和加到最后的分数当中(两个人共用一个分数),然后逆时针翻转他们,Alice 想要分数尽量打 Bob 想要分数尽量小 两个人每次的选择 都是最优的 求最后的分数
思路
玩的次数为 2k k最大为3 数据比较小,想暴力。
我们从后面往前思考
假如我们知道这个棋盘最后一步的状况,那么这时候轮到Bob 选择区域 那么它肯定会选择 和最小的一块区域
那么这个时候 再往上走一步 到 Alice 选择的时候, Alice 肯定会选择 和最大的一块区域 那么 回溯上去 就可以了
然后 只要dfs枚举每一种情况
AC代码
#pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <list>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <limits>
#define pb push_back
#define fi first
#define se second
#define L(on) ((on)<<1)
#define R(on) (L(on) | 1)
#define mkp(a, b) make_pair(a, b)
#define bug puts("***bug***");
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define CLR(a, b) memset(a, (b), sizeof(a));
#define syn_close ios::sync_with_stdio(false); cin.tie(0);
#define sp system("pause");
//#define gets gets_s
using namespace std;
typedef long long ll;
typedef long double ld;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector < vi > vvi;
const double PI = acos(-1.0);
const double EI = exp(1.0);
const double eps = 1e-8;
inline int read()
{
char c = getchar(); int ans = 0, vis = 1;
while (c < '0' || c > '9') { if (c == '-') vis = -vis; c = getchar(); }
while (c >= '0' && c <= '9') { ans = ans * 10 + c - '0'; c = getchar(); }
return ans * vis;
}
const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3fll;
const int maxn = (int)1e2 + 10;
const int MAXN = (int)1e4 + 10;
const ll MOD = (ll)1e9 + 7;
int k;
int arr[4][4];
void input()
{
k = read();
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
arr[i][j] = read();
}
int value(int i, int j)
{
return arr[i][j] + arr[i][j + 1] + arr[i + 1][j] + arr[i + 1][j + 1];
}
int select(int cur, int x, int y)
{
if (cur % 2)
return min(x, y);
return max(x, y);
}
int Index[2][4][2] =
{
1, 0,
0, 0,
1, 1,
0, 1,
0, 0,
0, 1,
1, 0,
1, 1,
};
int dfs(int cur)
{
if (cur == 2 * k - 1)
{
int ans = INF;
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
ans = min(ans, value(i, j));
return ans;
}
int ans = ((cur & 1) == 1 ? INF : 0);
for (int i = 0; i < 9; i++)
{
int x = i / 3, y = i % 3;
int f[4] = { arr[x][y], arr[x][y + 1], arr[x + 1][y], arr[x + 1][y + 1] };
for (int j = 0; j < 4; j++)
arr[x + Index[0][j][0]][y + Index[0][j][1]] = f[j];
ans = select(cur, ans, value(x, y) + dfs(cur + 1));
for (int j = 0; j < 4; j++)
arr[x + Index[1][j][0]][y + Index[1][j][1]] = f[j];
}
return ans;
}
int main()
{
int t = read();
while (t--)
{
input(); printf("%d\n", dfs(0));
}
}
17南宁区域赛 I - Rake It In 【DFS】的更多相关文章
- 高精度乘法-17南宁区域赛F -The Chosen One
题目大意:给你一个n,然后从1~n隔一个选一个,挑出一个集合然后从集合中继续隔一个挑一个,直到只有一个数,问最后一个数是多少?2<=n<=1050 例如n=5,先选出2,4最后选择4.n= ...
- The Maximum Unreachable Node Set 【17南宁区域赛】 【二分匹配】
题目链接 https://nanti.jisuanke.com/t/19979 题意 给出n个点 m 条边 求选出最大的点数使得这个点集之间 任意两点不可达 题目中给的边是有向边 思路 这道题 实际上 ...
- 17 南宁区域赛 F - The Chosen One 【规律】
题目链接 https://nanti.jisuanke.com/t/19972 题意 给出一个n 然后将 n 个数 标号为 1 -> n 按顺序排列 每次抽掉 奇数位的数 然后求最后剩下那个数字 ...
- 17南宁区域赛 J - Rearrangement 【规律】
题目链接 https://nanti.jisuanke.com/t/19976 题意 给出 一个n 然后 给出 2*n 个数 可以重新排列成两行 然后 相邻的两个数 加起来 不能被三整除 可以上下相邻 ...
- 2014年亚洲区域赛北京赛区现场赛A,D,H,I,K题解(hdu5112,5115,5119,5220,5122)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud 下午在HDU上打了一下今年北京区域赛的重现,过了5题,看来单挑只能拿拿铜牌,呜呜. ...
- HDU5558 Alice's Classified Message(合肥区域赛 后缀数组)
当初合肥区域赛的题(现场赛改了数据范围就暴力过了),可惜当初后缀数组算法的名字都没听过,现在重做下. i从1到n - 1,每次枚举rank[i]附近的排名,并记录当起点小于i时的LCP(rank[i] ...
- 36th成都区域赛网络赛 hdoj4039 The Social Network(建图+字符串处理)
这题是某年成都区域赛网络赛的一题. 这题思路非常easy,可是从时间上考虑,不妨不要用矩阵存储,我用的链式前向星. 採用线上查询.利用map对字符串编号,由于非常方便.要推荐的朋友,事实上就是朋友的朋 ...
- 【2013南京区域赛】部分题解 hdu4802—4812
上周末打了一场训练赛,题目是13年南京区域赛的 这场题目有好几个本来应该是我擅长的,但是可能是太久没做比赛了各种小错误代码写的也丑各种warusn trush搞得人很不爽 全场题之一的1002也没有想 ...
- hdu5080:几何+polya计数(鞍山区域赛K题)
/* 鞍山区域赛的K题..当时比赛都没来得及看(反正看了也不会) 学了polya定理之后就赶紧跑来补这个题.. 由于几何比较烂写了又丑又长的代码,还debug了很久.. 比较感动的是竟然1Y了.. * ...
随机推荐
- java继承机制
1 继承 关键字:extends java没有多重继承 实例 父类: package unit4; public class Base { public int publicVarofBase= ...
- 使用Hyper-V安装Ubuntu16.04 Server 网络配置
由于最近在研究Docker, 于是需要用到虚拟机,安装Ubuntu 16.04到Hyper-V并部署Docker.这个过程中填平了几个小坑,为了大家以后遇到类似情况节省时间,我将这几个小坑的问题和解决 ...
- SQL SERVER 2000安装教程图文详解
注意:Windows XP不能装企业版.win2000\win2003服务器安装企业版一.硬件和操作系统要求 下表说明安装 Microsoft SQL Server 2000 或 SQL Server ...
- -webkit-transition: all .2s ease-in-out;
W3C标准中对CSS3的transition这是样描述的:CSS的transition允许CSS的属性值在一定的时间区间内平滑地过渡.这种效果可以在鼠标单击.获得焦点.被点击或对元素任何改变中触发,并 ...
- android自定义View_3——Optimizing the View
前言:现在你已经有了一个自定义的view了,并且支持手势和过度动画等属性,现在你要确认这个view 有够快的速度,为了使其在UI上不会显得迟钝或是卡停,你要保证view动画,能每秒最好有60帧. 一: ...
- LeetCode Problem 169: Majority Element查找多数元素
描述:Given an array of size n, find the majority element. The majority element is the element that app ...
- python学习【第六篇】python迭代器与生成器
一.什么是迭代器 迭代器协议:对象必须提供一个next方法,执行该方法要么返回迭代中的下一项,要么就引起一个StopIteration异常,以终止迭代(只能往后走不能往前退) 可迭代对象:实现了迭代器 ...
- 《从零开始学Swift》学习笔记(Day 21)——函数返回值
原创文章,欢迎转载.转载请注明:关东升的博客 返回值3种形式:无返回值.单一返回值和多返回值. 无返回值函数 所谓无返回结果,事实上是Void类型,即表示没有数据的类型. 无返回值函数的语法格式有如下 ...
- 如何理解docker镜像build中的上下文
参考:https://yeasy.gitbooks.io/docker_practice/content/image/build.html 理解上线文概念非常重要,不然可能碰到一些奇怪的问题. 构建镜 ...
- SqlCommand对象-Transaction事务的使用
using (SqlConnection connection = new SqlConnection(connStr)) { SqlCommand sqlcmd = new SqlCommand() ...