计算机学院大学生程序设计竞赛(2015’12)Pick Game
Pick Game
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 119 Accepted Submission(s): 20
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.
One day, WKC plays this game with ZJS.
Both of them are clever students, so they will choose the best strategy.
WKC plays first, and he wants to know the maximal value he could get.
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).
1
2 2
9 8
7 6
16
总是望着曾经的空间发呆,那些说好不分开的朋友不在了,转身,陌路。 熟悉的,安静了, 安静的,离开了, 离开的,陌生了, 陌生的,消失了, 消失的,陌路了。
#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;
}
@执念 "@☆但求“❤”安★
下次我们做的一定会更好。。。。
为什么这次的题目是英文的。。。。QAQ...
计算机学院大学生程序设计竞赛(2015’12)Pick Game的更多相关文章
- hdu 计算机学院大学生程序设计竞赛(2015’11)
搬砖 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submissi ...
- 计算机学院大学生程序设计竞赛(2015’11)1005 ACM组队安排
1005 ACM组队安排 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Pro ...
- 计算机学院大学生程序设计竞赛(2015’12)Study Words
Study Words Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- 计算机学院大学生程序设计竞赛(2015’12)Polygon
Polygon Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Su ...
- 计算机学院大学生程序设计竞赛(2015’12)The Country List
The Country List Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- 计算机学院大学生程序设计竞赛(2015’12) 1008 Study Words
#include<cstdio> #include<cstring> #include<map> #include<string> #include&l ...
- 计算机学院大学生程序设计竞赛(2015’12) 1009 The Magic Tower
#include<cmath> #include<cstdio> #include<cstring> #include<algorithm> using ...
- 计算机学院大学生程序设计竞赛(2015’12) 1006 01 Matrix
#include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> ...
- 计算机学院大学生程序设计竞赛(2015’12) 1003 The collector’s puzzle
#include<cstdio> #include<algorithm> using namespace std; using namespace std; +; int a[ ...
随机推荐
- 【bzoj4568】【Scoi2016】幸运数字 (线性基+树上倍增)
Description A 国共有 n 座城市,这些城市由 n-1 条道路相连,使得任意两座城市可以互达,且路径唯一.每座城市都有一个幸运数字,以纪念碑的形式矗立在这座城市的正中心,作为城市的象征.一 ...
- Mysql 实现篮球比赛赛程中两支队伍的查询
表结构如下: 查询两支队伍的比赛情况,sql语句如下: SELECT t1.team_name,g.team1_score,g.team2_score,t2.team_name,g.gametime ...
- gdbt原理解析
链接: http://note.youdao.com/noteshare?id=aeb1c7a30c5f4b70e3fff51f28ee5c47 懒得复制到这里了,一开始是在有道云笔记上写的,这里的公 ...
- 安装sqlServer2012失败补救
今天拿着新电脑win10,装数据库2012,装了第一次,没装上,有一半的工具都失败了,慌了.. 连management studio都没装上,我用navicat也连不上. 卸了,第二次安装,装一半卡住 ...
- 洛谷 P1616 疯狂的采药
传送门 题目描述 Description LiYuxiang是个天资聪颖的孩子,他的梦想是成为世界上最伟大的医师.为此,他想拜附近最有威望的医师为师.医师为了判断他的资质,给他出了一个难题.医师把他 ...
- pl/sql小技巧
更正方法: 然后把Automatic statistics的勾选去掉,点击apply即可
- 10款GitHub上最火爆的国产开源项目
衡量一个开源产品好不好,看看产品在 GitHub 的 Star 数量就知道了.由此可见,GitHub 已经沦落为开源产品的“大众点评”了.一个开源产品希望快速的被开发者知道.快速的获取反馈,放到 Gi ...
- 利用广播调用后台服务方法并根据方法返回的内容更新UI
一.UI布局代码 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns ...
- Protostuff序列化和反序列化使用说明
原文:http://blog.csdn.net/zhglance/article/details/56017926 google原生的protobuffer使用起来相当麻烦,首先要写.proto文件, ...
- Java 实现 淘宝秒杀 聚划算 自己主动提醒 源代码
说明 本实例可以监控聚划算的抢购button,在聚划算整点聚的时间到达时自己主动弹开页面(URL自定义). 能够自己定义监控持续分钟数,同一时候还能够通过多线程加快刷新速度. 源代码 package ...