计算机学院大学生程序设计竞赛(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[ ...
随机推荐
- 解决centos7中ens33中不显示IP等问题
在虚拟机中安装centos7,输入ifconfig显示command not found.在sbin目录中发现没有ifconfig文件,这是因为centos7已经不使用 ifconfig命令了,已经用 ...
- Fruit Ninja
Fruit Ninja 时间限制:C/C++ 5秒,其他语言10秒 空间限制:C/C++ 262144K,其他语言524288K 64bit IO Format: %lld 题目描述 Fruit Ni ...
- *hdu5632Rikka with Array
$n \leq 10^300$,问所有$i<j$且$f_i>f_j$的$(i,j),1 \leq i \leq n,1 \leq j \leq n$数量.对某个数取模. $f(a,b,0/ ...
- 自定义Navigation按钮及Title
导航栏自带的按钮,时常不能满足要求,所以深深需要进行各种定制. 写一个UINavigationItem的category // UINavigationItem+CB_ChangeButton.h ...
- hdu3078 建层次树+在线LCA算法+排序
题意:n个点,n-1条边构成无向树,每个节点有权,Q次询问,每次或问从a->b的最短路中,权第k大的值,/或者更新节点a的权, 思路:在线LCA,先dfs生成树0,标记出层数和fa[](每个节点 ...
- BOJ 2773 第K个与m互质的数
算法是关键,得出1-m内的互质数,然后类推计算即可.下面有详细说明. #include<iostream> #include<cstring> using namespace ...
- 42.QT-QSqlQuery类操作SQLite数据库(创建、查询、删除、修改)详解
Qt 提供了 QtSql 模块来提供平台独立的基于 SQL 的数据库操作.这里我们所说的“平台 独立”,既包括操作系统平台,也包括各个数据库平台,Qt支持以下几种数据库: QT自带SQLITE数据库, ...
- Java开发笔记(一百零一)通过加解锁避免资源冲突
前面介绍了如何通过线程同步来避免多线程并发的资源冲突问题,然而添加synchronized的方式只在简单场合够用,在一些高级场合就暴露出它的局限性,包括但不限于下列几点:1.synchronized必 ...
- 【js html】对于<img>图片的引用填充,src可以给什么值?
平时多见的<img>的使用,常见于如下: <img class="img-responsive img-rounded" src="static/img ...
- Thrift --- 支持双向通信
[问题] Thrift采用了C/S模型,不支持双向通信:client只能远程调用server端的RPC接口,但client端则没有RPC供server端调用,这意味着,client端能够主动与serv ...