日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ACM CPC2017 Naning I 题 Rake It In (博弈树) alpha-beta 剪枝

發布時間:2024/1/18 编程问答 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ACM CPC2017 Naning I 题 Rake It In (博弈树) alpha-beta 剪枝 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

新學習了知識點;

博弈樹 alpha-beta 剪枝:

https://blog.csdn.net/qq_27008079/article/details/60869054

還有一個國外的網站, 講的很明晰:

http://web.cs.ucla.edu/~rosen/161/notes/alphabeta.html


Rake It In

時間限制:?1 Sec?? 內存限制:?128 MB
提交:?73?? 解決:?13
[ 提交][ 狀態][ 討論版][命題人: admin]

題目描述

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 ?nal score. However for Bob, his goal is to minimize the ?nal score.
In order to test how good this game is, you are hired to write a program which can play the game. Speci?cally,? given the starting con?guration, they would like a program to determine the ?nal score when both players are? entirely rational.

輸入

The input contains several test cases and the first line provides an integer t (1 ≤ t ≤ 200) which is the number of? test cases.
Each case contains five lines. The first line provides the integer 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 1 to 10.

輸出

For each case, output an integer in a line which is the predicted ?nal 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

提示

來源

ICPC2017?Naning?



【思路】


? ?用alph-beta 剪枝, 不然的話會超時, 說白了 就是 DFS


【code】

/* * Date:4/8/2018 * Tile: ACM ICPC nanning * Category: 博弈樹 alpha-beta 剪枝 (DFS) */ #include <iostream> #include <bits/stdc++.h>typedef long long ll; const int MAXN=1e5+5; const int INF=0x3f3f3f3f;using namespace std;int k; int mp[5][5]; int dfs(int h,int a[5][5],int x,int y,int player,int alpha,int beta,int s) {int sum=0;int newa[5][5];for(int i=1;i<=4;i++)for(int j=1;j<=4;j++)newa[i][j]=a[i][j];if(h){for(int i=x;i<=x+1;i++)for(int j=y;j<=y+1;j++)sum+=newa[i][j];swap(newa[x][y],newa[x+1][y]);swap(newa[x][y],newa[x+1][y+1]);swap(newa[x][y],newa[x][y+1]);}if( h==2*k)return s+sum;for(int i=1;i<=3;i++){for(int j=1;j<=3;j++){if(player)beta=min(beta,dfs(h+1,newa,i,j,player^1,alpha,beta,s+sum));elsealpha=max(alpha,dfs(h+1,newa,i,j,player^1,alpha,beta,s+sum));if(beta<=alpha){break;}}if(beta<=alpha){break;}}return player?beta:alpha; } int main() {int t;scanf("%d",&t);while(t--){scanf("%d",&k);for(int i=1;i<=4;i++)for(int j=1;j<=4;j++)scanf("%d",&mp[i][j]);int ans=dfs(0,mp,0,0,0,-INF,INF,0);printf("%d\n",ans);}return 0; }

轉載于:https://www.cnblogs.com/sizaif/p/8822640.html

總結

以上是生活随笔為你收集整理的ACM CPC2017 Naning I 题 Rake It In (博弈树) alpha-beta 剪枝的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。