HDU 4568 Hunter(最短路径+DP)(2013 ACM-ICPC长沙赛区全国邀请赛)
The area can be represented as a N*M rectangle. Any points of the rectangle is a number means the cost of research it,-1 means James can't cross it, James can start at any place out of the rectangle, and explore point next by next. He will move in the rectangle and bring out all treasures he can take. Of course, he will end at any border to go out of rectangle(James will research every point at anytime he cross because he can't remember whether the point are researched or not).
Now give you a map of the area, you must calculate the least cost that James bring out all treasures he can take(one point up to only one treasure).Also, if nothing James can get, please output 0.

#include <cstdio>
#include <queue>
#include <utility>
#include <iostream>
#include <cstring>
using namespace std;
typedef pair<int, int> PII; const int MAXN = ; int mat[MAXN][MAXN], tx[], ty[];
int dis[MAXN][MAXN], di[][];
bool ist[MAXN][MAXN];
int post[MAXN][MAXN];
int n, m, k; #define pos(x, y) (x*MAXN+y) int fx[] = {-,,,};
int fy[] = {,,,-}; void min_path(int st_x, int st_y, int now) {
priority_queue<PII> que;
que.push(make_pair(-mat[st_x][st_y], pos(st_x, st_y)));
memset(dis, 0x3f, sizeof(dis));
dis[st_x][st_y] = mat[st_x][st_y];
while(!que.empty()) {
int abc = -que.top().first, tmp = que.top().second; que.pop();
int x = tmp / MAXN, y = tmp % MAXN;
if(abc != dis[x][y]) continue;
for(int i = ; i < ; ++i) {
int newx = x + fx[i], newy = y + fy[i];
if( <= newx && newx < n && <= newy && newy < m) {
if(mat[newx][newy] == -) continue;
if(dis[newx][newy] > mat[newx][newy] + dis[x][y]) {
dis[newx][newy] = mat[newx][newy] + dis[x][y];
que.push(make_pair(-dis[newx][newy], pos(newx, newy)));
if(ist[newx][newy] && dis[newx][newy] < di[now][post[newx][newy]])
di[now][post[newx][newy]] = dis[newx][newy];
}
}
else if(dis[x][y] < di[now][k]) di[now][k] = dis[x][y];
}
}
} int dp[][];
int ans, sum; int dfs(int u, int use) {
if(dp[u][use] < 0x3f3f3f3f) return dp[u][use];
if(use == ) {
return dp[u][use] = di[u][k];
}
for(int i = ; i < k; ++i) {
if(use & ( << i))
dp[u][use] = min(dp[u][use], di[u][i] + dfs(i, use ^ ( << i)));
}
return dp[u][use];
} void solve() {
memset(dp, 0x3f, sizeof(dp));
ans = 0x7fff7fff;
for(int i = ; i < k; ++i)
ans = min(ans, di[i][k] + dfs(i, ( << i) ^ (( << k) - )));
} void printdi() {
for(int i = ; i < k; ++i) {
for(int j = ; j <= k; ++j) printf("%d ", di[i][j]);
printf("\n");
}
} int main() {
int T;
scanf("%d", &T);
while(T--) {
scanf("%d%d", &n, &m);
for(int i = ; i < n; ++i)
for(int j = ; j < m; ++j) scanf("%d", &mat[i][j]);
scanf("%d", &k);
memset(ist, , sizeof(ist));
sum = ;
for(int i = ; i < k; ++i) {
scanf("%d%d", &tx[i], &ty[i]);
ist[tx[i]][ty[i]] = true;
post[tx[i]][ty[i]] = i;
sum += mat[tx[i]][ty[i]];
}
memset(di, 0x3f, sizeof(di));
for(int i = ; i < k; ++i) min_path(tx[i], ty[i], i);
//printdi();
solve();
printf("%d\n", ans - sum);
}
}
HDU 4568 Hunter(最短路径+DP)(2013 ACM-ICPC长沙赛区全国邀请赛)的更多相关文章
- HDU 4571 Travel in time ★(2013 ACM/ICPC长沙邀请赛)
[题意]给定N个点,每个点有一个停留所需的时间Ci,和停留能够获得的满意度Si,有M条边,每条边代表着两个点走动所需的时间ti,现在问在规定的T时间内从指定的一点S到E能够获得的最大的满意度是多少?要 ...
- HDU 4758——Walk Through Squares——2013 ACM/ICPC Asia Regional Nanjing Online
与其说这是一次重温AC自动机+dp,倒不如说这是个坑,而且把队友给深坑了. 这个题目都没A得出来,我只觉得我以前的AC自动机的题目都白刷了——深坑啊. 题目的意思是给你两个串,每个串只含有R或者D,要 ...
- HDU 4571 Travel in time(最短路径+DP)(2013 ACM-ICPC长沙赛区全国邀请赛)
Problem Description Bob gets tired of playing games, leaves Alice, and travels to Changsha alone. Yu ...
- hdu 4751 Divide Groups bfs (2013 ACM/ICPC Asia Regional Nanjing Online 1004)
SDUST的训练赛 当时死磕这个水题3个小时,也无心去搞其他的 按照题意,转换成无向图,预处理去掉单向的边,然后判断剩下的图能否构成两个无向完全图(ps一个完全图也行或是一个完全图+一个孤点) 代码是 ...
- 2013 ACM/ICPC 长沙网络赛J题
题意:一个数列,给出这个数列中的某些位置的数,给出所有相邻的三个数字的和,数列头和尾处给出相邻两个数字的和.有若干次询问,每次问某一位置的数字的最大值. 分析:设数列为a1-an.首先通过相邻三个数字 ...
- 2013 ACM/ICPC 长沙现场赛 A题 - Alice's Print Service (ZOJ 3726)
Alice's Print Service Time Limit: 2 Seconds Memory Limit: 65536 KB Alice is providing print ser ...
- 2013 ACM/ICPC 长沙现场赛 C题 - Collision (ZOJ 3728)
Collision Time Limit: 2 Seconds Memory Limit: 65536 KB Special Judge There's a round medal ...
- HDU 4573 Throw the Stones(动态三维凸包)(2013 ACM-ICPC长沙赛区全国邀请赛)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4573 Problem Description Remember our childhood? A fe ...
- HDU 4569 Special equations(枚举+数论)(2013 ACM-ICPC长沙赛区全国邀请赛)
Problem Description Let f(x) = anxn +...+ a1x +a0, in which ai (0 <= i <= n) are all known int ...
随机推荐
- 如何编写及运行JS
JS也是一种脚本语言,他可以有两种方式在HTML页面进行引入,一种是外联,一种是内部. 外联JS的写法为: <script src="相对路径"></ ...
- 【2013 ICPC亚洲区域赛成都站 F】Fibonacci Tree(最小生成树+思维)
Problem Description Coach Pang is interested in Fibonacci numbers while Uncle Yang wants him to do s ...
- (Nagios)-check_hpasm[HP]
Nagios Check_hp HP 2014年11月18日 下午 08:49 https://IP:2381 [root@nagios ~]# tar zxvf check_hp_blad ...
- mysql使用数据库
哈哈 只能怪自己太菜哈 刚接触这个MySQL没多久 今天用终端登陆MySQL的时候mysql -u root -p 然后就想看看自己的数据库 我用的MySQL的客户端是navicat for mysq ...
- go加密算法:非对称加密(一)--RSA
椭圆曲线加密__http://blog.51cto.com/11821908/2057726 // MyRas.go package main import ( "crypto/rand&q ...
- 【Keil】Keil5的安装和破...
档案的话网上很多的,另外要看你开发的是哪种内核的芯片 如果是STC的,就安装C51 如果是STM的,就安装MDK 当然市面上有很多芯片的,我也没用过那么多种,这里也就不列举了 至于注册机,就是...恩 ...
- python通过mongoengine中connect函数连接多个数据库
mongoengine支持程序同时连接多个数据库,这些数据库可以位于一个或多个mongo之中,通过alias名称区分不同的连接即可. 可以通过switch_db切换到不同的数据库,进行读写操作,swi ...
- 北京Uber优步司机奖励政策(4月4日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- IAR调试cc2541串口遇到的Warning : Possible IDATA stack overflow detected
1. 遇到的错误如下,似乎是栈空间不够使用 2. 修改界面如下,增加IDATA的大小,不过最大似乎是0XFF.
- 利尔达NB-IOT模组Coap数据AT+NMGS发送时返回-513的原因
1. 利尔达NB-IOT模组使用AT+NMGS发送数据,返回-513的问题,大致有3种可能性,在硬件上,模组的射频电路分为A型和B型模组,所以烧写固件的时候,也要分为A和B型固件,如果烧写反了,那么R ...