计算机学院大学生程序设计竞赛(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[ ...
随机推荐
- wsgi 简介
原文博客地址 http://blog.csdn.net/on_1y/article/details/18803563
- Honey Heist
5092: Honey Heist 时间限制: 1 Sec 内存限制: 128 MB 题目描述 0x67 is a scout ant searching for food and discover ...
- 标准C程序设计七---13
Linux应用 编程深入 语言编程 标准C程序设计七---经典C11程序设计 以下内容为阅读: <标准C程序设计>(第7版) 作者 ...
- python--爬取http://www.kuaidaili.com/并保存为xls
代码如下: 复制在python3上先试试吧^_^ # -*- coding: utf-8 -*- """ Created on Mon Jun 12 13:27:59 2 ...
- 使用 ftrace 调试 Linux 内核,第 3 部分
内核头文件 include/linux/kernel.h 中描述了 ftrace 提供的工具函数的原型,这些函数包括 trace_printk.tracing_on/tracing_off 等.本文通 ...
- JavaScript ES6中,export与export default
自述: 本来是对new Vue()和export default比较懵的,查了一下,发现我理解错了两者的关系,也没意识到export与export default的区别,先简单的记录一下基本概念,后续 ...
- 洛谷——P1141 01迷宫
P1141 01迷宫 题目描述 有一个仅由数字0与1组成的n×n格迷宫.若你位于一格0上,那么你可以移动到相邻4格中的某一格1上,同样若你位于一格1上,那么你可以移动到相邻4格中的某一格0上. 你的任 ...
- python type()函数
我怎么把一个变量的类型写入文件?a = 3type(a)貌似返回的是type类型,不能打印,也不能用文件的write怎么半,或者怎么转换成srt之类的? type()函数得到的是一个类型而不是字符串, ...
- luogu P1351 联合权值
题目描述 无向连通图G 有n 个点,n - 1 条边.点从1 到n 依次编号,编号为 i 的点的权值为W i ,每条边的长度均为1 .图上两点( u , v ) 的距离定义为u 点到v 点的最短距离. ...
- NOIP临考经验(转)
[COGS]NOIP临考经验 1. 提前15分钟入场,此时静坐调整心态,适当的深呼吸 2. 打开编辑器并调整为自己喜欢的界面 3. 熟悉文件目录,写好准确无误的代码模板 4. 压缩包或许还不能 ...