我是靠谱客的博主 英俊羽毛,这篇文章主要介绍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.

样例输入

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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

样例输出

复制代码
1
2
3
4
20 40 63 71
思路:因为数据范围比较小,所可以暴力搜索。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#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内容请搜索靠谱客的其他文章。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部