DFS CCPC2017 南宁I题
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,回溯,感觉没太多好讲的
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=acos(-);
const int mod=1e9+;
const int inf=<<;
const int maxn=1e5+;
int a[][];
int k;
int val(int i,int j){
return a[i][j]+a[i+][j]+a[i][j+]+a[i+][j+];
}
void rotat(int i,int j){
int a1=a[i][j],a2=a[i][j+],a3=a[i+][j],a4=a[i+][j+];
a[i][j]=a2,a[i][j+]=a4,a[i+][j]=a1,a[i+][j+]=a3;
}
void retat(int i,int j){
int a1=a[i][j],a2=a[i][j+],a3=a[i+][j],a4=a[i+][j+];
a[i][j]=a3,a[i][j+]=a1,a[i+][j]=a4,a[i+][j+]=a2;
}
int dfs(int t){
int ans;
if(t==*k-){
ans=inf;
for(int i=;i<;i++)
for(int j=;j<;j++)
ans=min(ans,val(i,j));
return ans;
}
else if(t%==){
ans=;
for(int i=;i<;i++)
for(int j=;j<;j++){
rotat(i,j);
int tmp=val(i,j);
ans=max(ans,tmp+dfs(t+));
retat(i,j);
}
}
else{
ans=inf;
for(int i=;i<;i++)
for(int j=;j<;j++){
rotat(i,j);
int tmp=val(i,j);
ans=min(ans,tmp+dfs(t+));
retat(i,j);
}
}
return ans;
}
int main(){
int T;scanf("%d",&T);
while(T--){
scanf("%d",&k);
for(int i=;i<;i++){
for(int j=;j<;j++){
scanf("%d",&a[i][j]);
}
}
cout<<dfs()<<endl;
}
return ;
}
DFS CCPC2017 南宁I题的更多相关文章
- hdu 1312:Red and Black(DFS搜索,入门题)
Red and Black Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- Codeforces Gym 100338I TV Show 傻逼DFS,傻逼题
Problem I. TV ShowTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest ...
- 2017ICPC南宁 M题 The Maximum Unreachable Node Set【二分图】
题意: 找出不能相互访问的点集的集合的元素数量. 思路: 偏序集最长反链裸题. 代码: #include<iostream> #include<cstring> using n ...
- hdu1242 Rescue DFS(路径探索题)
这里我定义的路径探索题指 找某路能够到达目的地,每次走都有方向,由于是探索性的走 之后要后退 那些走过的状态都还原掉 地址:http://acm.hdu.edu.cn/showproblem.php? ...
- 湖南省第六届省赛题 Biggest Number (dfs+bfs,好题)
Biggest Number 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 You have a maze with obstacles and non-zero di ...
- hdu 2553:N皇后问题(DFS遍历,水题)
N皇后问题 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- zzulioj--1730--通信基站(全排列+dfs)(好题)
1730: 通信基站 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 28 Solved: 11 SubmitStatusWeb Board Desc ...
- 1506 传话 (暴力DFS或者Tarjan模板题)
题目描述 Description 一个朋友网络,如果a认识b,那么如果a第一次收到某个消息,那么会把这个消息传给b,以及所有a认识的人. 如果a认识b,b不一定认识a. 所有人从1到n编号,给出所有“ ...
- 【LeetCode】深搜DFS(共85题)
[98]Validate Binary Search Tree [99]Recover Binary Search Tree [100]Same Tree [101]Symmetric Tree [1 ...
随机推荐
- 全排列+字符串查找|扑克排序|2014年蓝桥杯A组题解析第六题-fishers
标题:扑克序列 A A 2 2 3 3 4 4, 一共4对扑克牌.请你把它们排成一行. 要求:两个A中间有1张牌,两个2之间有2张牌,两个3之间有3张牌,两个4之间有4张牌. 请填写出所有符合要求的排 ...
- cumtoj 一起来选课
一起来选课 题目地址:http://192.168.173.163/JudgeOnline/problem.php?cid=1019&pid=7 题目 明泽私立大学有n门课程提供给大一的同学来 ...
- oracle 之 基础操作
//删除存在的表空间及数据 drop tablespace TS_YYGL including contents and datafiles 若是出现了提示 错误 导致无法全部删除,那么就执行以下语句 ...
- 怎么在父窗口调用它页面的iframe里面数据,进行操作?
注:在服务器下操作有效果,本地无效 document.getElementById("taskdetail1").contentWindow.test(a) document.ge ...
- 批处理bat标准化获取当前系统日期的几种方法,补0
首先有两个推荐的方案. 一: for /f "tokens=2 delims==" %%a in ('wmic path win32_operatingsystem get Loc ...
- 【译】第19节---数据注解-NotMapped
原文:http://www.entityframeworktutorial.net/code-first/notmapped-dataannotations-attribute-in-code-fir ...
- HDU 4302 Holedox Eating(multiset)
http://acm.hdu.edu.cn/showproblem.php?pid=4302 题意: 在一条直线上,会有多条命令,如果是0,那么就会在x位置处出现一个蛋糕,如果是1,某人就会找到最近的 ...
- BZOJ 1497: [NOI2006]最大获利(最大权闭合图)
http://www.lydsy.com/JudgeOnline/problem.php?id=1497 题意: 思路: 论文题,只要看过论文的话就是小菜一碟啦~ 每个用户群i作为一个结点分别向相应的 ...
- CSS深入
块元素:div.h1.p等等. 列表的样式: /*使用系统提供的一些样式:例如无序.有序都可以使用circle*/ ul{ list-style-type: circle; } ol{ list-st ...
- Vue--vux组件库
各种组件demo源码~ https://doc.vux.li/zh-CN/