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

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

hdu1044【bfs+dfs】

2019-11-10 20:12:16
字體:
供稿:網(wǎng)友

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,已經(jīng)搜到獲得最大價值 代碼:

#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表示當(dāng)前節(jié)點,time表花費的時間,V表價值void dfs(int kind , int time, int V) // kind==0 表示起點,kind==M+1表示終點,其他表示寶藏{ if (time > L || ans == Max) return; // 超出時間或已經(jīng)得到最大價值 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"); }}
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
国产精品裸体一区二区三区| 亚洲色婷婷一区二区三区| 亚洲系列第一页| 一区二区三区视频在线免费观看| 欧美精选一区二区| 在线观看一区视频| 国产三级精品三级在线观看国产| 亚洲一区三区| 亚洲自拍偷拍欧美| 欧美激情 亚洲| 欧美色国产精品| 日韩国产精品一区二区三区| 日韩精品成人一区二区在线观看| 欧美扣逼视频| 亚洲精品乱码久久久久| 在线观影网站| 国产欧美一区二区在线观看| 触手亚洲一区二区三区| 老司机精品视频导航| 欧美人与禽猛交乱配视频| 日日噜噜夜夜狠狠久久波多野| 紧缚奴在线一区二区三区| 欧美激情在线有限公司| 欧洲精品在线视频| 芒果视频成人app| 免费在线国产| 精品夜夜嗨av一区二区三区| 四季av在线一区二区三区| 国产亚洲成av人片在线观看| 色姑娘综合天天| 91成人伦理在线电影| 国产精品久久久一区二区三区| 久久这里只有精品6| 久久精品国产福利| 精品色999| 欧美女v视频| 男女视频在线观看免费| 久久国产视频精品| 97人妻精品视频一区| 爽好久久久欧美精品| 一区二区三区在线免费视频| 国产日韩精品一区二区| 91黄色在线观看| **网站欧美大片在线观看| 欧美精品卡一卡二| 男女激情视频一区| 一区二区三区四区视频免费观看| 后入内射欧美99二区视频| 欧美成人精品欧美一级乱| 日韩一区av| 久久影院视频免费| 成人av电影在线网| 婷婷激情图片久久| 成人伊人精品色xxxx视频| 三年中文高清在线观看第6集| 成人成人成人在线视频| 欧美无砖专区一中文字| 亚洲精品国产精品国自| 国产一区二区三区精品在线| 91久久国产综合| 亚洲精品97久久中文字幕无码| 欧美婷婷六月丁香综合色| 四虎成人精品永久免费av| 国产欧美日韩伦理| 波多野结衣天堂| 中文字幕日韩一区二区不卡| 久久.com| 欧美性猛交xxxx黑人猛交| 在线观看中文字幕的网站| 国产夫妻在线视频| 亚洲人成人一区二区三区| 欧美成人se01短视频在线看| 日韩精品在线视频观看| 神马久久桃色视频| 久久久国产高清| 亚洲欧美日韩成人网| 成人h动漫精品一区| 黄色网址免费看| 91污片在线观看| 国产亚洲精品免费| 麻豆入口视频在线观看| 在线看日韩av| 色yeye香蕉凹凸一区二区av| 亚洲一区日韩精品中文字幕| 免费av网站大全久久| 国产色播av在线| 你懂的免费在线观看视频网站| 久久久久久久久久久免费| 潘金莲一级淫片aaaaa免费看| 精品久久在线播放| 亚洲国产又黄又爽女人高潮的| 午夜不卡av免费| 久久久久久久九九九九| 99久久久无码国产精品| 国产视频91在线| 国产精品久久久久av| 成人精品一区二区| 在线色欧美三级视频| 亚洲v中文字幕| 丰乳肥臀在线| 日本一区二区不卡在线| 亚洲一区二区四区蜜桃| 欧美成人aaaaⅴ片在线看| 精品剧情在线观看| 欧美精品99| 久久久久久久久久久久久女过产乱| 精品久久久久久一区二区里番| 激情视频一区二区三区| 手机在线免费看片| a片在线免费观看| 国产日本欧美一区二区| 黄色成人av在线| 国产手机视频在线| 日韩精品不卡| 精品国产免费av| 亚洲日本视频在线观看| 亚洲国内精品| 无人码人妻一区二区三区免费| 一区二区三区在线视频免费| 欧美黄色一区二区| 国产在线a不卡| 久久国内精品自在自线400部| 亚洲综合免费观看高清完整版在线| 无码国产精品一区二区高潮| 国产人妻黑人一区二区三区| 欧洲在线视频| eeuss国产一区二区三区四区| 欧美日韩国产一二| 黄网页免费在线观看| 免费日韩一区二区三区| 欧美调教在线| 日韩精彩视频在线观看| 久久中文字幕视频| 国内毛片毛片毛片毛片毛片| 亚洲在线www| 亚洲精品va在线观看| www视频完整版| 能在线观看的av| 菠萝蜜视频国产在线播放| 精品成人av一区| 欧美视频中文字幕| 99精品福利视频| 无吗不卡中文字幕| 免费男女羞羞的视频网站中文字幕妖精视频| 亚洲国产精品自拍视频| 国产伦精品一区二区三区视频青涩| 欧美成aaa人片免费看| 国内精品久久影院| 亚洲一区二区三区日本久久九| 国产毛片一区二区三区| 黄色av一区| 在线视频亚洲欧美中文| 亚洲欧美日韩另类精品一区二区三区| 亚洲成人av在线电影| 视频黄页在线| 草裙成人精品一区二区三区| 欧美日韩免费做爰视频| 老鸭窝一区二区| 欧美亚洲另类在线一区二区三区| 九九九伊在线综合永久| 国产精品综合久久久久| 欧美a v在线播放| 国产色婷婷在线| 日本在线一区二区三区| 欧美激情videoshd| 伊人免费视频2| 日韩成人亚洲| 国产真实伦在线观看| 中文视频一区| 136福利精品导航| 国产精品久久久久久一区二区三区| 国产乱人伦偷精品视频免下载| 91高清在线观看视频| 97在线观看视频免费| 中文字幕人成不卡一区| 欧美成人国产| 成人精品视频在线播放| 国产成人在线视频网址| 中文字幕一区二区三区四区欧美| 久久免费看av| 日韩 欧美一区二区三区| 美丽的姑娘在线观看免费动漫| 国产精品一区二区在线观看网站| a毛片在线免费观看| 激情懂色av一区av二区av| 久久精品色欧美aⅴ一区二区| 亚洲国产精品一区二区尤物区| 亚洲国产成人一区二区| 一区二区三区视频免费| 久久精品波多野结衣| 欧美三级情趣内衣| 欧美日韩免费高清一区色橹橹| 综合久久久久| 亚洲国产日韩综合久久精品| 午夜福利理论片在线观看| 天天躁夜夜躁狠狠是什么心态| 午夜激情av在线| 在线观看欧美www| 亚洲国产精品va| 亚洲欧美日韩区| 天堂中文资源在线观看| 欧美成人精品1314www| 日韩免费在线看| 邻家有女韩剧在线观看国语| 福利小视频在线观看| 欧美又粗又大又爽| chinese偷拍一区二区三区| 久久久久久国产精品免费播放| 久久不卡国产精品一区二区| 日本高清视频一区二区| 欧美一区二区精品在线| 欧美不卡激情三级在线观看| 国产91精品网站| 91精品国产综合久久精品| 热国产热中文视频二区| 亚洲一级中文字幕| 国产99久久精品一区二区 夜夜躁日日躁| 久久成人国产精品| 欧美丰满嫩嫩电影| 午夜精品久久久久久久白皮肤| 欧美精品国产白浆久久久久| 国产免费视频一区二区三区| 一道本视频在线观看| 68精品国产免费久久久久久婷婷| 一个人www欧美| 亚洲电影一级片| 国产一级在线免费观看| 嫩草影院发布页| 日韩hd视频在线观看| 夜夜嗨av一区二区三区四区| 免费大片黄在线观看视频网站| 亚洲精品99久久久久中文字幕| 欧美日韩视频一区二区| www.午夜色大片| 91精品视频免费观看| 日韩精品中文字幕一区二区| 欧美激情精品久久久久久小说| 成人动漫网站在线观看| 日韩欧美视频一区二区| 另类国产精品一区二区| 在线成人私人影院| 神马久久久久久久久久久| 最近免费中文字幕大全免费第三页| 91精品久久久久久久久久不卡| 色婷婷久久av| 热草久综合在线| 日本aⅴ免费视频一区二区三区| h片视频在线观看| 亚洲五月激情网| 天天干天天插天天操| 国产免费一级| 自拍偷拍在线视频| 国产精品高清网站| 你懂得在线观看| 神马午夜dy888| 日韩在线免费| 亚洲精品综合在线| 国产欧美va欧美不卡在线| thepron国产精品| 日韩中文字幕在线免费观看| 韩国av一区二区三区四区| 国产精品91久久久| 久色视频网站| 在线碰免费视频在线观看| 欧美videos另类齐全| 亚洲精品中文字幕在线观看| 中文字幕在线观看亚洲| 成人毛片视频免费看| 国产乱精品一区二区三区| 麻豆精品视频在线观看视频| 国产欧美日韩最新| missav|免费高清av在线看| 国产欧美日韩精品高清二区综合区| 国产一级片免费在线观看| 亚洲一二三四| 欧美激情自拍| 黄色视屏网站在线免费观看| 亚洲国产一区二区三区在线观看| 最好看的2019年中文视频| 免费观看黄色一级视频| 激情综合色播激情啊| 激情五月***国产精品| 欧日韩在线视频| 色老头在线一区二区三区| av在线综合网| 黄页网站在线观看免费| 精品日韩免费| 亚洲欧美成人精品| 无码人妻精品一区二区三区66| 色资源在线观看| 欧美精品一区二区高清在线观看| 8av国产精品爽爽ⅴa在线观看| 国产原创视频在线观看| 日韩污视频在线观看| 日本dhxxxxxdh14日本| 九义人在线观看完整免费版电视剧| 天堂在线中文字幕| 国产成人福利短视频app| 97人妻精品一区二区三区免| 成人性生交大片免费看小说| 日本aⅴ亚洲精品中文乱码| 无人视频在线观看免费| 国产精品免费观看高清| 97免费高清电视剧观看| 毛片大全在线观看| 亚洲乱码一区av黑人高潮| 日本在线中文字幕一区| av免费在线观| 最近中文字幕大全中文字幕免费| 免费av网站在线观看| 中文字幕の友人北条麻妃| 欧美成人国产| 欧美性高清videossexo| 国产超碰在线观看| 亚洲成人第一| 日韩中文字幕亚洲| 一区二区视频在线播放| 最新亚洲人成网站在线观看| 国产一区二区三区在线观看网站| 亚洲一区二区三区久久久| 亚洲精品亚洲人成在线观看| 91免费视频国产| 亚洲欧美日韩一区二区在线| 91蝌蚪视频九色| 在线精品视频在线观看高清| 黄页网站在线观看视频| 在线精品高清中文字幕| 国产男女av|