我是靠谱客的博主 英俊羽毛,最近开发中收集的这篇文章主要介绍ACM-ICPC 2017 Asia Nanning-I:Rake It In(DFS),觉得挺不错的,现在分享给大家,希望可以做个参考。

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×4 board is created with 16 values placed on the board. Starting with player Alice, each player in a round selects a  2×2 region of the board, adding the sum of values in the region to the score indicator, and then rotating these four values 90 degrees counterclockwise.

After 2k 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 (1t200) which is the number of test cases.

Each case contains five lines. The first line provides the integer k(1k3). Each of the following four lines contains four integers indicating the values on the board initially. All values are integers between 1 to 10.

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
思路:因为数据范围比较小,所可以暴力搜索。

#include<bits/stdc++.h>
using namespace std;
int a[5][5],n;
int dfs(int k)
{
if(k>2*n)return 0;
int ans;
ans=(k%2?0:1e9+7);
for(int i=1;i<=3;i++)
{
for(int j=1;j<=3;j++)
{
swap(a[i][j],a[i+1][j]);
swap(a[i][j+1],a[i][j]);
swap(a[i+1][j+1],a[i][j+1]);
if(k%2)ans=max(ans,a[i][j]+a[i+1][j]+a[i][j+1]+a[i+1][j+1]+dfs(k+1));
else ans=min(ans,a[i][j]+a[i+1][j]+a[i][j+1]+a[i+1][j+1]+dfs(k+1));
swap(a[i+1][j+1],a[i][j+1]);
swap(a[i][j+1],a[i][j]);
swap(a[i][j],a[i+1][j]);
}
}
return ans;
}
int main()
{
int T;cin>>T;
while(T--)
{
scanf("%d",&n);
for(int i=1;i<=4;i++)
{
for(int j=1;j<=4;j++)scanf("%d",&a[i][j]);
}
printf("%dn",dfs(1));
}
return 0;
}




最后

以上就是英俊羽毛为你收集整理的ACM-ICPC 2017 Asia Nanning-I:Rake It In(DFS)的全部内容,希望文章能够帮你解决ACM-ICPC 2017 Asia Nanning-I:Rake It In(DFS)所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(53)

评论列表共有 0 条评论

立即
投稿
返回
顶部