亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 學院 > 開發設計 > 正文

hdu1044【bfs+dfs】

2019-11-10 19:17:29
字體:
來源:轉載
供稿:網友

Collect More Jewels

Time Limit: 2000/1000 MS (java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7334 Accepted Submission(s): 1705

PRoblem Description It is written in the Book of The Lady: After the Creation, the cruel god Moloch rebelled against the authority of Marduk the Creator.Moloch stole from Marduk the most powerful of all the artifacts of the gods, the Amulet of Yendor, and he hid it in the dark cavities of Gehennom, the Under World, where he now lurks, and bides his time.

Your goddess The Lady seeks to possess the Amulet, and with it to gain deserved ascendance over the other gods.

You, a newly trained Rambler, have been heralded from birth as the instrument of The Lady. You are destined to recover the Amulet for your deity, or die in the attempt. Your hour of destiny has come. For the sake of us all: Go bravely with The Lady!

If you have ever played the computer game NETHACK, you must be familiar with the quotes above. If you have never heard of it, do not worry. You will learn it (and love it) soon.

In this problem, you, the adventurer, are in a dangerous dungeon. You are informed that the dungeon is going to collapse. You must find the exit stairs within given time. However, you do not want to leave the dungeon empty handed. There are lots of rare jewels in the dungeon. Try collecting some of them before you leave. Some of the jewels are cheaper and some are more expensive. So you will try your best to maximize your collection, more importantly, leave the dungeon in time.

Input Standard input will contain multiple test cases. The first line of the input is a single integer T (1 <= T <= 10) which is the number of test cases. T test cases follow, each preceded by a single blank line.

The first line of each test case contains four integers W (1 <= W <= 50), H (1 <= H <= 50), L (1 <= L <= 1,000,000) and M (1 <= M <= 10). The dungeon is a rectangle area W block wide and H block high. L is the time limit, by which you need to reach the exit. You can move to one of the adjacent blocks up, down, left and right in each time unit, as long as the target block is inside the dungeon and is not a wall. Time starts at 1 when the game begins. M is the number of jewels in the dungeon. Jewels will be collected once the adventurer is in that block. This does not cost extra time.

The next line contains M integers,which are the values of the jewels.

The next H lines will contain W characters each. They represent the dungeon map in the following notation:

[*] marks a wall, into which you can not move; [.] marks an empty space, into which you can move; [@] marks the initial position of the adventurer; [<] marks the exit stairs; [A] - [J] marks the jewels.

Output Results should be directed to standard output. Start each case with “Case #:” on a single line, where # is the case number starting from 1. Two consecutive cases should be separated by a single blank line. No blank line should be produced after the last test case.

If the adventurer can make it to the exit stairs in the time limit, print the sentence “The best score is S.”, where S is the maximum value of the jewels he can collect along the way; otherwise print the Word “Impossible” on a single line.

Sample Input 3

4 4 2 2 100 200


@A B<


4 4 1 2 100 200


@A B<


12 5 13 2 100 200


B……… .***.* @…A….<


Sample Output Case 1: The best score is 200.

Case 2: Impossible

Case 3: The best score is 300.

一個迷宮,L時間后倒塌,里面有M個寶藏。問能否逃出,如果逃出,得到的最大價值是多少? 寶藏由大寫字母【A】~【J】表示,‘*’表示墻,‘.’表示路,‘@’表示起點,‘<’表示出口。 題解: 寶藏最多十個,可以bfs找出寶藏,起點,出口相互之間的最短距離,然后dfs搜索最大能獲得的價值。 剪枝:ans==Max,已經搜到獲得最大價值 代碼:

#include <iostream>#include <string>#include <cstring>#include <cstdio>#include <cmath>#include <cstdlib>#include <algorithm>#include <queue>#include <map>#define MST(s,q) memset(s,q,sizeof(s))#define INF 0x3f3f3f3f#define MAXN 9999using namespace std;struct Node{ int x, y; int sum;} s, u, v;int W, H, L, M, ans, Max; // Max保存所有寶藏價值的和char Map[100][100];int move_x[4] = {1, -1, 0, 0}, move_y[4] = {0, 0, 1, -1};int value[11];int path[20][20]; // 保存(起點,終點,各寶藏 ) 它們直接的最短距離,最多bfs地圖十幾次bool vis[100][100];bool visited[20];// 求kind到其他點的距離void bfs(int x, int y, int kind) // kind==0 表示起點,kind==M+1表示終點,1-M表示寶藏{ queue<Node> Q; s.x = x, s.y = y, s.sum = 0; MST(vis, 0); Q.push(s); vis[x][y] = 1; while (!Q.empty()) { u = Q.front(); Q.pop(); for (int i = 0; i < 4; i++) { v.x = u.x + move_x[i], v.y = u.y + move_y[i]; if (v.x >= 0 && v.x < H && v.y >= 0 && v.y < W && !vis[v.x][v.y] && Map[v.x][v.y] != '*') { vis[v.x][v.y] = 1; v.sum = u.sum + 1; if (Map[v.x][v.y] != '.') { if (Map[v.x][v.y] == '@') path[kind][0] = v.sum; else if (Map[v.x][v.y] == '<') path[kind][M + 1] = v.sum; else path[kind][Map[v.x][v.y] - 'A' + 1] = v.sum; } Q.push(v); } } }}// kind表示當前節點,time表花費的時間,V表價值void dfs(int kind , int time, int V) // kind==0 表示起點,kind==M+1表示終點,其他表示寶藏{ if (time > L || ans == Max) return; // 超出時間或已經得到最大價值 if (kind == M + 1) { ans = max(ans, V); return; } for (int i = 1; i <= M + 1; i++) { if (!visited[i]) { visited[i] = 1; dfs(i, time + path[kind][i], V + value[i - 1]); visited[i] = 0; } }}int main(){ int T, sx, sy, icase = 1; cin >> T; while (T--) { cin >> W >> H >> L >> M; Max = 0; for (int i = 0; i < M; i++) { scanf("%d", &value[i]); Max += value[i]; } value[M] = 0; for (int i = 0; i < H; i++) scanf("%s", Map[i]); MST(path, INF); // 把距離初始為最大 for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) { if (Map[i][j] == '@') bfs(i, j, 0); else if (Map[i][j] == '<')bfs(i, j, M + 1); else if (Map[i][j] >= 'A' && Map[i][j] <= 'J') bfs(i, j, Map[i][j] - 'A' + 1); } MST(visited, 0); visited[0] = 1; ans = -1; dfs(0, 0, 0); printf("Case %d:/n", icase++); if (ans != -1) printf("The best score is %d./n", ans); else printf("Impossible/n"); if (T) printf("/n"); }}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
亚洲va欧美va在线观看| 久久国产一区二区三区| 亚洲理论在线a中文字幕| 欧美巨乳在线观看| 成人亚洲综合色就1024| 亚洲片av在线| 国产精品第三页| 欧美大片欧美激情性色a∨久久| 亚洲xxx视频| 欧美日韩亚洲成人| 欧美专区日韩视频| 日韩电影在线观看永久视频免费网站| 欧美成aaa人片在线观看蜜臀| 亚洲综合国产精品| 一区二区三区www| 欧洲成人在线视频| 日韩av免费一区| 国产精品自产拍在线观看中文| 亚洲国产欧美在线成人app| 国产综合在线观看视频| 成人h猎奇视频网站| 国产精品人成电影在线观看| 精品国偷自产在线视频| 4388成人网| 国产精品 欧美在线| 欧美精品制服第一页| 欧美性xxxx极品hd欧美风情| 性欧美在线看片a免费观看| 欧美高清在线观看| 国产日韩欧美中文在线播放| 成人av在线网址| 欧美亚洲国产日本| 亚洲国产精品人久久电影| 欧美成人免费va影院高清| 国产女同一区二区| 久久久精品视频在线观看| 亚洲免费影视第一页| 亚洲欧美制服第一页| 亚洲人成电影网站色xx| www国产亚洲精品久久网站| 精品亚洲一区二区三区在线观看| 国产精品成人久久久久| 亚洲一区二区三区四区在线播放| 日韩亚洲精品电影| 538国产精品一区二区免费视频| 欧美日韩亚洲一区二区| 欧美巨大黑人极品精男| 国产精品第七影院| 亚洲第一色中文字幕| 国产精品久久在线观看| 欧洲成人免费视频| 精品美女国产在线| 国产亚洲精品成人av久久ww| 欧美一级高清免费| 国产精品日韩欧美综合| 欧美日韩国产一中文字不卡| 久久久爽爽爽美女图片| 孩xxxx性bbbb欧美| 欧美高清视频一区二区| 亚洲精品一区二区三区婷婷月| 国产一区二区日韩| 欧美日韩国产91| 欧美黑人又粗大| 北条麻妃一区二区三区中文字幕| 国产成人精品在线观看| 中文字幕一区二区三区电影| 国产精品久久久久久亚洲调教| 欧美日韩中文字幕日韩欧美| 97视频在线播放| 久久99精品久久久久久青青91| 91在线播放国产| 欧美黄色免费网站| 久久久爽爽爽美女图片| 国产精品白丝av嫩草影院| 午夜精品福利电影| 在线亚洲国产精品网| 久久久人成影片一区二区三区| 国产香蕉精品视频一区二区三区| 久久好看免费视频| 国产精品成久久久久三级| 中文字幕亚洲国产| 欧美性在线观看| 欧美成人午夜免费视在线看片| 欧洲亚洲免费在线| 91av在线视频观看| 久久精品精品电影网| 亚洲一区二区三区乱码aⅴ| 国产69精品久久久久9999| 日韩av在线免费看| 97精品在线观看| 久久亚洲精品一区二区| 亚洲欧美综合精品久久成人| 国产成人精品视频在线观看| 国产精品久久久久久久久久小说| 亚洲码在线观看| 亚洲自拍偷拍色图| 51精品国产黑色丝袜高跟鞋| 欧美劲爆第一页| 国产视频精品久久久| 中文字幕在线亚洲| 欧美日韩亚洲一区二区| 日韩精品免费一线在线观看| 日韩电影大全免费观看2023年上| 国产成人精品av| 91爱爱小视频k| 81精品国产乱码久久久久久| 伊人久久免费视频| 亲子乱一区二区三区电影| 欧美又大又粗又长| 国产成人小视频在线观看| 国产亚洲精品美女久久久久| 91久久久在线| 欧美午夜视频一区二区| 中文字幕亚洲欧美日韩2019| 日韩免费中文字幕| 国产精品一区久久久| 一区二区三区动漫| 91久久夜色精品国产网站| 欧美另类极品videosbestfree| 亚洲欧美一区二区三区四区| 久久精品视频网站| 久久成人人人人精品欧| 午夜精品久久久久久久男人的天堂| 91久久综合亚洲鲁鲁五月天| 日韩欧美亚洲一二三区| 欧美性猛交xxxx富婆| 久久精品国产99国产精品澳门| 国产精品18久久久久久首页狼| 成人观看高清在线观看免费| 91亚洲人电影| 欧美极品少妇全裸体| 欧美色道久久88综合亚洲精品| 久久在线免费观看视频| 欧美激情视频播放| 欧美一区二区色| 国产精品嫩草影院久久久| 色偷偷88888欧美精品久久久| 亚洲视频在线观看视频| 91精品视频免费观看| 欧美性69xxxx肥| 欧美电影院免费观看| 亚洲精品欧美日韩专区| 欧美一乱一性一交一视频| 久久久久亚洲精品国产| 国产精品久久久久久久天堂| 日韩av在线精品| 久久天天躁狠狠躁夜夜躁2014| 国产视频在线一区二区| 色婷婷av一区二区三区久久| 国内精品视频一区| 不卡av在线播放| 国产69久久精品成人看| 亚洲第一福利网站| 啪一啪鲁一鲁2019在线视频| 国产精品电影久久久久电影网| 亚洲国产一区二区三区四区| 精品偷拍各种wc美女嘘嘘| 欧美一区二区三区四区在线| 福利精品视频在线| 色综合导航网站| 欧美xxxx18性欧美| 亚洲精品网站在线播放gif| 热99在线视频| 中日韩美女免费视频网站在线观看|