计算机学院大学生程序设计竞赛(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[ ...
随机推荐
- __new__ 与 __init__的区别
原文地址:http://www.cnblogs.com/ifantastic/p/3175735.html 单例模式 class Singleton(object): def __new__(cls, ...
- 【AIM Tech Round 5 (Div. 1 + Div. 2) 】
A:https://www.cnblogs.com/myx12345/p/9844152.html B:https://www.cnblogs.com/myx12345/p/9844205.html ...
- DP的序--Codeforces956E. Wardrobe
$n \leq 10000$个盒子,有高度,高度总和$\leq 10000$,盒子有重要的和不重要的,问最多有多少重要盒子的底端在区间$[L,R]$. 这是个入门级的DP,但需要一点胆量MD这题能放D ...
- 【shell】shell编程(三)-if,select,case语句
通过前两篇文章,我们掌握了shell的一些基本写法和变量的使用,以及基本数据类型的运算.那么,本次就将要学习shell的结构化命令了,也就是我们其它编程语言中的条件选择语句及循环语句. 不过,在学习s ...
- hdu4888 多校B 最大流以及最大流唯一判断+输出方案
题意,给一个矩阵,告诉你每行和.每列和,并且限制所填数不大于k,问矩阵是否唯一. 经典建图不说了,第一次遇到判断最大流唯一性的,学习了:用dfs来判断残网中是否还存在环,若存在,则表明绕这个环走一圈, ...
- 将数字转换成Excel表头格式的字母序号
/** * 从0开始算起,0-25转A-Z * @param num * @return Character.valueOf((char)((num-1)+65))+&quo ...
- .NET Core 3.0之创建基于Consul的Configuration扩展组件
写在前面 经过前面三篇关于.NET Core Configuration的文章之后,本篇文章主要讨论如何扩展一个Configuration组件出来.如果前面三篇文章没有看到,可以点击如下地址访问 .N ...
- 成长笔记 - mysql-5.5.25-winx64安装步骤(及密码修改问题)
操作系统:Windows 7 64位 下载地址: http://download.mysql.cn/src/2012/0602/5611.html 1. 将mysql-5.5.25-winx64.zi ...
- easyui combobox模糊查询
用easyui框架开发的攻城狮恐怕都遇到过这样一个问题,就是在新增页面combobox下拉框需要支持模糊查询,但是输入不是combobox中Data里面的值的时候,点击保存,依然是可以新增进去的,这样 ...
- ios实现下载图片的裁减和显示
使用如下的方法可以裁减的同时保证了不丢失像素. - (void)connectionDidFinishLoading:(NSURLConnection *)connection{ // Set ...