Pick Game
来源:互联网 发布:json和js对象的区别 编辑:程序博客网 时间:2024/05/16 18:38
Problem Description
One day, hh plays a game with GL. On a n*m matrix, each gird has a value. The player could only choose the gird that is adjacent to at least two empty girds (A grid outside the matrix also regard as empty). Adjacent means two girds share a common edge. If one play chooses one gird, he will get the value and the gird will be empty. They play in turn.
GL and hh are clever boys. They will choose the best strategy, hh plays first, and he wants to know the maximal value he could get.
GL and hh are clever boys. They will choose the best strategy, hh plays first, and he wants to know the maximal value he could get.
Input
On the first line of input is a single positive integer, 1<=T<=50, specifying the number of test cases to follow.
Each test case begins with two numbers n and m. (2<=n, m<=5)
Then n lines follow and each lines with m numbers Vij. (0< Vij <=1000)
Each test case begins with two numbers n and m. (2<=n, m<=5)
Then n lines follow and each lines with m numbers Vij. (0< Vij <=1000)
Output
Output the maximal value hh could get.
Sample Input
12 29 87 6
Sample Output
16
Source
2014-03-PK2
题意:n*m的矩阵,2个人轮流取一个格子的值,要求取的格子四周至少有2个空的格子,hh先取,求他能取得的最大值
分析:记忆化搜索,dp表示当前状态hh比GL多的值,0表示这一个未取,1表示已取,一共最多有2^25种状态,用hash散列来存
#include <iostream>#include<cstdio>#include<cstring>#include<string>#include<algorithm>#define mod 10007#define N 10010#include<vector>using namespace std;vector<int> v[N],dp[N];int n,m,cnt,Map[6][6];int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}};bool ok(int x,int y){ if(x<n&&x>=0&&y<m&&y>=0) return true; return false;}int Gets(int st){ int ret=0; for(int i=0;i<cnt;i++){ if(((1<<i)&st)==0){ ret+=Map[i/m][i%m]; } } return ret;}int cal(int st){ int ret=0,i; for(i=0;i<cnt;i++) if((1<<i)&st) ret++; return ret;}int dfs(int st){ int next,ans,i,j,tmp,x,y,xx,yy; x=st%mod; for(y=v[x].size()-1;y>=0;y--){ if(v[x][y]==st) return dp[x][y]; } if(cal(st)==cnt-1) return Gets(st); ans=-20006; for(i=0;i<cnt;i++){ if(((1<<i)&st)==0){ x=i/m; y=i%m; tmp=0; for(j=0;j<4;j++){ xx=x+dir[j][0]; yy=y+dir[j][1]; if(!ok(xx,yy)||(ok(xx,yy)&&(((1<<(xx*m+yy))&st)))){ tmp++; } } if(tmp>=2){ next=(1<<i) | st; ans=max(ans,Map[x][y]-dfs(next)); } } } v[st%mod].push_back(st); dp[st%mod].push_back(ans); return ans;}int main(){ int t,i,j; scanf("%d",&t); while(t--){ for(i=0;i<mod;i++){ dp[i].clear(); v[i].clear(); } scanf("%d%d",&n,&m); for(i=0;i<n;i++){ for(j=0;j<m;j++){ scanf("%d",&Map[i][j]); } } cnt=n*m; printf("%d\n",(dfs(0)+Gets(0))/2); } return 0;}
0 0
- Pick Game
- Pick Picknic (card game)
- 计算机学院大学生程序设计竞赛(2015’12)Pick Game
- NBA: Kobe Bryant, Michael Jordan and the Greatest Pick-Up Game Ever
- HDU计算机学院大学生程序设计竞赛(2015’12)1007 Pick Game
- pick公式
- Pick原理
- pick 定理
- Pick apples
- Pick Apples
- Pick numbers
- pick up
- Pick公式
- Pick定理
- Pick定理
- Pick定理
- pick定理
- cherry-pick
- Java高效编程之二【对所有对象都通用的方法】
- Ubuntu下手机USB 显示??? insufficient permissions for device
- D3D中的世界矩阵,视图矩阵,投影矩阵
- JS字符串拼接的问题
- foreach使用方法 和 枚举使用方法
- Pick Game
- "The MathType DLL cannot be found.Please reinstall MathType"问题解决
- Linux oracle 10g 修改数据库的sid和dbname
- C#秒数转DateTime
- 简单的C程序设计
- 19英寸 6U 机架的U 等行业术语
- ios获取手机的ip
- oracle 的动态采样技术
- ActionScript实现喷泉效果