The designers have come up with a new simple game called “Rake It In”. Two players, Alice and Bob, initially select an integer k and initialize a score indicator. An 4 \times 44×4 board is created with 16 values placed on the board. Starting with player Alice, each player in a round selects a 2 \times 22×2 region of the board, adding the sum of values in the region to the score indicator, and then rotating these four values 9090 degrees counterclockwise.

After 22k rounds in total, each player has made decision in k times. The ultimate goal of Alice is to maximize the final score. However for Bob, his goal is to minimize the final score.

In order to test how good this game is, you are hired to write a program which can play the game. Specifically, given the starting configuration, they would like a program to determine the final score when both players are entirely rational.

Input

The input contains several test cases and the first line provides an integer t (1 \le t \le 200)t(1≤t≤200)which is the number of test cases.

Each case contains five lines. The first line provides the integer k (1 \le k \le 3)k(1≤k≤3). Each of the following four lines contains four integers indicating the values on the board initially. All values are integers between 11 to 1010.

Output

For each case, output an integer in a line which is the predicted final score.

样例输入

4
1
1 1 2 2
1 1 2 2
3 3 4 4
3 3 4 4
2
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
3
1 1 4 4
4 4 1 1
1 1 4 4
1 4 1 4
3
1 2 3 4
5 1 2 3
4 5 1 2
3 4 5 1

样例输出复制

20
40
63
71

之前搜有大佬说需要用到alpha-beta剪枝,但是数据范围非常小,似乎不需要

还是贴个链接吧,如果有需要的可以看看https://blog.csdn.net/qq_27008079/article/details/60869054

暴力DFS,回溯,感觉没太多好讲的

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 const double pi=acos(-1);
 5 const int mod=1e9+7;
 6 const int inf=1<<30;
 7 const int maxn=1e5+7;
 8 int a[4][4];
 9 int k;
10 int val(int i,int j){
11     return a[i][j]+a[i+1][j]+a[i][j+1]+a[i+1][j+1];
12 }
13 void rotat(int i,int j){
14     int a1=a[i][j],a2=a[i][j+1],a3=a[i+1][j],a4=a[i+1][j+1];
15     a[i][j]=a2,a[i][j+1]=a4,a[i+1][j]=a1,a[i+1][j+1]=a3;
16 }
17 void retat(int i,int j){
18     int a1=a[i][j],a2=a[i][j+1],a3=a[i+1][j],a4=a[i+1][j+1];
19     a[i][j]=a3,a[i][j+1]=a1,a[i+1][j]=a4,a[i+1][j+1]=a2;
20 }
21 int dfs(int t){
22     int ans;
23     if(t==2*k-1){
24         ans=inf;
25         for(int i=0;i<3;i++)
26         for(int j=0;j<3;j++)
27         ans=min(ans,val(i,j));
28         return ans;
29     }
30     else if(t%2==0){
31         ans=0;
32         for(int i=0;i<3;i++)
33         for(int j=0;j<3;j++){
34             rotat(i,j);
35             int tmp=val(i,j);
36             ans=max(ans,tmp+dfs(t+1));
37             retat(i,j);
38         }
39     }
40     else{
41         ans=inf;
42         for(int i=0;i<3;i++)
43         for(int j=0;j<3;j++){
44             rotat(i,j);
45             int tmp=val(i,j);
46             ans=min(ans,tmp+dfs(t+1));
47             retat(i,j);
48         }
49     }
50     return ans;
51 }
52 int main(){
53     int T;scanf("%d",&T);
54     while(T--){
55         scanf("%d",&k);
56         for(int i=0;i<4;i++){
57             for(int j=0;j<4;j++){
58                 scanf("%d",&a[i][j]);
59             }
60         }
61         cout<<dfs(0)<<endl;
62     }
63     return 0;
64 }

转载于:https://www.cnblogs.com/qingjiuling/p/10407196.html

DFS CCPC2017 南宁I题相关推荐

  1. hdu1242 Rescue DFS(路径探索题)

    hdu1242 Rescue DFS(路径探索题) 这里我定义的路径探索题指 找某路能够到达目的地,每次走都有方向,由于是探索性的走 之后要后退 那些走过的状态都还原掉 地址:http://acm.h ...

  2. leetcode之DFS+BFS+DSU刷题总结2

    leetcode之DFS+BFS+DSU刷题总结2 1-对称二叉树 题目链接:题目链接戳这里!!! 思路1:迭代法 一棵二叉树,左右子树分别进队,如果左右子树都为空,则结束遍历,如果左右子树仅一个为空 ...

  3. 小雨的矩阵(DFS三参数模板题)

    E-小雨的矩阵 题目描述 小雨有一个n×n 的矩阵,起点在(1,1),终点在(n,n),只能向下或向右走,且每次只能走 1 步. 矩阵上每个点都有一个点权a(i,j). 求走到终点的路径有多少不同的点 ...

  4. bfs dfs 搜索入门模板题

    bfs & dfs 题目链接:https://vjudge.net/contest/404511 1.最短路(bfs) (1)一维最短路 D - Catch That Cow 题目大意: 在一 ...

  5. Leetcode51 n皇后 DFS+回溯(模板题)

    n皇后 链接 n皇后问题是说给定n*n的棋盘和n个皇后,求出所有合理的摆法.所谓合理的摆法是说n个皇后可以平安无事的处于棋盘上.国际象棋中皇后可以横着走.竖着走.斜着走,只要处于这些位置,皇后就会杀掉 ...

  6. 【LeetCode】深搜DFS(共85题)

    [98]Validate Binary Search Tree [99]Recover Binary Search Tree [100]Same Tree [101]Symmetric Tree [1 ...

  7. POJ 2230 Watchcow 欧拉回路的DFS解法(模板题)

    Watchcow Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 9974 Accepted: 4307 Special Judg ...

  8. java dfs算法蓝桥杯题_【蓝桥杯省赛JavaB组真题详解】四平方和(2016)_疼疼蛇的博客-CSDN博客...

    原文作者:疼疼蛇 原文标题:[蓝桥杯省赛JavaB组真题详解]四平方和(2016) 发布时间:2021-02-26 15:00:01 题目描述 四平方和 四平方和定理,又称为拉格朗日定理: 每个正整数 ...

  9. POJ 1154题解,此题不难理解方法就是DFS,属于水题。不过有一些细节要注意。...

    1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<string.h> 4 #include<iostre ...

  10. [Offer收割]编程练习赛2 hihocoder 1272 买零食 (DFS 或 dp 水题)

    时间限制:5000ms 单点时限:1000ms 内存限制:256MB 描述 小Ho很喜欢在课间去小卖部买零食.然而不幸的是,这个学期他又有在一教的课,而一教的小卖部姐姐以冷若冰霜著称.第一次去一教小卖 ...

最新文章

  1. 面试官:磁盘 IO 变高,你怎么分析?
  2. git commit Please tell me who you are it config --global user.email you@example.com
  3. java contains 通配符_java删除文件支持通配符
  4. centos 7上ambari安装试用
  5. 亚马逊出的平板电脑_亚马逊Fire HD 8 Plus评测:适合看视频和轻度游戏的廉价平板...
  6. 阿里云研究员叔同:云原生是企业数字创新的最短路径
  7. 行人属性数据集pa100k_基于InceptionV3的多数据集联合训练的行人外观属性识别方法与流程...
  8. 坚果nuts 加速 官网_坚果?R2?正式发布:延续经典设计,提供旗舰性能,而且是“下一代电脑”...
  9. 2020年华工计算机应用基础随堂作业,《计算机应用基础》随堂练习-2020年华工网络教育.docx...
  10. 【ECG实践篇(1)】MIT-BIH数据库数据解析的方法以及使用rdann获取人工标注注释的方法
  11. python菜鸟教程w-【读书】Django教程(菜鸟教程)
  12. 每天学点5G-5G NEF
  13. 博弈论笔记(0)—— 参考书籍及前置知识
  14. 什么是炎症(inflammation)?抗生素?//2021-2-12
  15. 智能编程计算机表演赛,中国儿童青少年计算机表演赛在京闭幕
  16. 计算机两个硬盘的作用,固态硬盘时代谈谈双硬盘(固态+机械硬盘)的好处
  17. java序列化算法透析_java--序列化及其算法透析
  18. 什么是汽车SOA架构?【长期更新】【800字】【原创】
  19. 傅里叶描述子、HOG特征描述子原理及matlab代码
  20. 迷宫最短路径问题(数据结构4.4.3 拓展)

热门文章

  1. poj 2263 Heavy Cargo floyd基础,就是输入的时候处理字符串纠结一点!!!!
  2. 如何在 Mac 上的“磁盘工具”中使用密码加密和保护储存设备?
  3. 冰点还原精灵Deep Freeze for mac 系统还原工具
  4. After Effects报警最后日志消息是:<760504><SonyRawDecoder><5>
  5. 如何设置Parallels Desktop游戏模式?
  6. 管理Kubernetes集群时需要关注的关键指标
  7. IMWeb Conf2018 Native跨端融合总结
  8. Flex tree加三状态的Checkbox
  9. 【好书试读】Docker全攻略
  10. [转]iOS技巧之获取本机通讯录中的内容,解析通讯录源代码