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. TypeError: Caught TypeError in DataLoader worker process 0.
  2. php soap webservice 实例
  3. 剑指offer 算法 (举例让抽象具体化)
  4. Asp.Net customErrors与httpErrors的区别
  5. LiveVideoStack线上分享第三季(十四):FLV封装格式介绍及解析
  6. 基于.NetCore3.1系列 —— 日志记录之初识Serilog
  7. jzoj4616-[NOI2016模拟7.12]二进制的世界【平衡规划,dp】
  8. activity启动流程_以AMS视角看Activity启动过程
  9. mkfs.xfs 命令找不到的解决方法
  10. matlab 振动,振动系统固有特性的matlab计算
  11. excel导入,用反射匹配字段名
  12. python批量读取图片并复制入word_提取出 Word 文档里的图片  并利用 python 批量转换格式...
  13. 公司测试员用例写得乱七八糟,测试总监制定了这份《测试用例编写规范》
  14. mysql按时间查询的优化_mysql按时间查询优化的方法
  15. ⑤CSS浮动学成在线网实例
  16. springmvc出现404错误!
  17. 我的世界java版电脑下载,我的世界国际版电脑版下载
  18. Android---universal-image-loader应用
  19. the quieter you become,the more you could see.
  20. LED的高显指是什么意思?

热门文章

  1. 麻辣鲜妻(80后爆笑爱情日志)
  2. 温故而知新:查看端口占用情况以及DOS中的管道操作/重定向操作
  3. axure rp9是什么软件?如何在Mac中安装使用?
  4. FastGitHub for Mac(GitHub下载扩展工具)
  5. Vectorworks 2022 SP2 for mac(首选3D建筑设计软件)
  6. 如何自定义Mac 启动台每页的排列数量?
  7. 如何使用ImageRanger Pro Edition mac版创建缩略图?
  8. RDS数据订阅服务使用说明
  9. Rootkit之ntrootkit的配置使用
  10. android 文件加密源码