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

首頁 > 學院 > 開發(fā)設計 > 正文

hdu1044【bfs+dfs】

2019-11-10 20:21:18
字體:
供稿:網(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表示當前節(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ā)表
青青草视频在线免费观看| 亚洲午夜激情免费视频| 黄色小视频在线观看| 日本一区影院| 91碰在线视频| xxxx性欧美| 视频免费一区| 久久av红桃一区二区禁漫| 国产伦精品一区二区三区在线观看| 99re6热在线精品视频| 深夜福利一区| jazzjazz国产精品麻豆| 在线免费观看一区二区| 成人免费黄色网址| 有码一区二区三区| 杨幂一区欧美专区| 乱人伦中文视频在线| 99久久精品情趣| 99热最新在线| www.爱久久.com| 久久精品视频在线观看| 日韩精品一区二区三区四| 在线观看国产日韩| 欧美日韩一区二区三区| 欧美日韩一道本| 成人app下载| 成人三级高清视频在线看| 成人乱人伦精品视频在线观看| 99在线免费观看视频| 欧美拍拍视频| 久久久久久久久97黄色工厂| 欧美+日本+国产+在线a∨观看| 久久精品女人毛片国产| 91cn在线观看| 午夜伊人狠狠久久| av官网在线播放| 黄色性视频网站| www国产精品av| www.亚洲欧美| 亚洲视频axxx| 欧美乱妇23p| 国产一区丝袜| 国产一级久久久久毛片精品| 欧美精品激情| 免费国产阿v视频在线观看| 欧美国产一区二区| 五月婷婷激情网| 亚洲视频免费播放| 国产二区视频在线观看| 91久久国产婷婷一区二区| 中文字幕永久在线观看| 国产精品中文在线| 国产日韩一区二区| 久久精品性爱视频| 高清在线一区二区| 国产一卡2卡3卡4卡网站免费| 日本韩国在线观看| 成人永久看片免费视频天堂| 黄色片视频在线播放| 国产成人精品免费网站| 亚洲一区二区综合| 国产精品久久久久桃色tv| 日本少妇精品亚洲第一区| 日韩免费高清视频网站| 一区二区三区在线免费观看| 日韩欧美精品免费| 国产亚洲一区二区三区不卡| 欧美黄色直播| 在线精品视频小说1| 国产主播福利在线| 91美女福利视频高清| 中文字幕一二三四区| 男人的j进女人的j一区| 亚洲少妇在线| 久久99精品国产一区二区三区| 亚洲乱亚洲乱妇| 狂野欧美性猛交xxxx| 日韩在线不卡| 人妻妺妺窝人体色www聚色窝| 无码一区二区三区在线| 日韩精品一区二区三区| 国产精品av久久久久久无| 欧美a在线播放| 欧美日韩中文| 国产女主播一区二区三区| 8v天堂国产在线一区二区| 91精品国产91久久久久麻豆 主演| 日韩精品视频在线免费观看| 97色在线视频| 亚洲欧美日韩综合精品网| 亚洲第一在线综合在线| 视频精品一区二区三区| 亚洲天堂av免费在线观看| 91激情在线观看| 亚洲综合激情| 久久久噜久噜久久综合| 色婷婷综合激情| 97久久人人超碰caoprom| 国产亚洲精品aa| 日韩三级成人av网| 影音先锋中文在线播放| 国产一区二区三区四区五区3d| 91精品婷婷国产综合久久竹菊| 黄色网址在线免费观看| 久久99精品波多结衣一区| 91亚洲视频| 特级黄国产片一级视频播放| 中文在线观看免费网站| 91精品国产综合久久久久| 亚洲免费在线| 国产性猛交╳xxx乱大交| 欧美aaa在线| 韩国日本美国免费毛片| 国产精品自拍小视频| 日韩黄色三级在线观看| 最新国产拍偷乱拍精品| 亚洲精品中文综合第一页| 亚洲第一av色| 欧洲视频一区| 少妇高潮爽到全身痉挛抽搐| 精品久久在线| 一区二区不卡| 91久久精品一区二区别| 美国一级片在线免费观看视频| 日韩不卡免费高清视频| 韩国免费在线视频| 在线看不卡av| 小视频免费在线观看| 国产成人拍精品视频午夜网站| 3d性欧美动漫精品xxxx软件| 亚洲电影一级黄| 亚洲成人中文在线| 欧洲精品久久一区二区| 91禁国产网站| 三级欧美韩日大片在线看| 欧美亚洲爱爱另类综合| 国产精品成人一区二区| 免费看涩涩视频软件| 在线丨暗呦小u女国产精品| 欧美日韩不卡中文字幕在线| 91精品久久久久久久久久久| 国产一区二区三区视频在线| 妞干网视频在线观看| 亚洲最快最全在线视频| 国产探花视频在线观看| 内射后入在线观看一区| 久草福利资源在线观看| 男女视频在线观看| 日本韩国在线视频爽| 国产精品jizz在线观看老狼| 国产精品探花一区二区在线观看| 俄罗斯嫩小性bbwbbw| 免费又黄又爽又色的视频| 国产精品免费一区二区三区在线观看| 欧美午夜不卡视频| 日韩免费一级片| 北条麻妃一二三区| 亚洲一区亚洲二区| 久久精品最新免费国产成人| 国产91aaa| 91精品国产亚洲| 日韩亚洲一区中文字幕| 在线亚洲一区二区| 欧美日韩国产不卡在线看| 国产麻豆一精品一男同| 久久亚洲专区| 欧美在线视频日韩| 国产天堂素人系列在线视频| 亚洲国产精品成人无久久精品| 亚洲女同av| 高清在线视频日韩欧美| 99久久er热在这里只有精品66| 国产一区二区精品免费| 亚洲天堂第一区| www.偷拍.com| 美女精品久久| 久久久一区二区三区捆绑**| 色八戒一区二区三区| 欧美日韩网站| y97精品国产97久久久久久| 天堂av中文在线| 日韩av在线高清| 午夜精品福利一区二区三区蜜桃| 国产精品区一区二区三区| 秋霞一区二区三区| 亚洲人的天堂男人爽爽爽| 92看片淫黄大片一级| 高清毛片aaaaaaaa**| 亚洲一区二区乱码| 日本福利视频| 青青操视频在线观看| 黄视频网站在线看| 久久三级福利| 青青在线观看视频中文字| 蜜桃av网站| 久草在线新免费首页资源站| 亚洲另类自拍| 美女高潮黄又色高清视频免费| 日韩欧美三级视频| 久久资源中文字幕| 免费三片在线播放| 欧美日韩爱爱视频| 日本午夜免费一区二区| 一本大道久久精品| 久久成年人视频| 久久久久久久中文字幕| 欧美制服丝袜第一页| 伊人久久大香线蕉av超碰演员| 亚洲激情一区二区| 国产成人一二| 欧美电影免费观看| 国产区一区二区三| 91精品人妻一区二区三区蜜桃欧美| 久久在线观看视频| 日韩中文字幕高清| 在线观看免费中文字幕| 久热国产在线| 中文区中文字幕免费看| 久久久久亚洲精品国产| 在线播放精品一区二区三区| 91丨九色丨海角社区| 日韩精品最新网址| 欧美又大又硬又粗bbbbb| 欧美在线视频不卡| 一个人看的视频www| 国产一区二区高清视频| 黄色影视在线观看| 免费av片在线观看一道本| 黄色大片在线免费看| 一区二区三区视频在线| 亚洲婷婷在线| 午夜国产福利在线| 国产日韩欧美一二三区| 一级黄色免费片| 26uuu成人网一区二区三区| 亚洲一区二区三区| 美女一区二区视频| 秋霞精品一区二区三区| 色综合天天综合网国产成人网| jvid福利在线一区二区| 国产又黄又大又爽| 成人在线观看视频网站| 成人做爰视频www网站小优视频| 男女啪啪免费观看| 亚洲综合免费视频| 91欧美精品成人综合在线观看| 久久99精品久久久久久动态图| 美女黄色网址| 999久久久精品一区二区| 精品人妻一区二区三区四区在线| h片在线免费观看| 欧美一区亚洲一区| 欧美日韩激情在线一区二区三区| 婷婷激情四射网| 国产粉嫩一区二区三区在线观看| 亚州国产精品| 伊人久久青草| 日韩视频在线观看免费| 欧美日韩精品国产| 19禁羞羞电影院在线观看| 97热在线精品视频在线观看| 在线亚洲国产精品网站| 欧洲久久久久久| 一本色道久久加勒比精品| 伪装者在线观看完整版免费| 特级毛片在线| 久久er99热精品一区二区三区| 亚洲女人天堂视频| 国产有码在线观看| 欧美一级一级性生活免费录像| 黄色欧美日韩| 欧美性猛交99久久久久99| www国产成人| 99精品老司机免费视频| 国产一区二区不卡视频| 欧美 日韩 成人| 激情视频综合网| 日本一区二区三区国色天香| 日本人体一区二区| 激情五月婷婷综合网| 中文有码久久| 欧美一区二区视频观看视频| 欧美大片免费观看在线观看网站推荐| 国产精品一区久久| 精品免费日韩av| 人妻无码一区二区三区四区| 丰满少妇中文字幕| 亚洲网友自拍偷拍| 在线观看成人小视频| 十大免费污污软件| 欧美视频精品| 中文字幕国产在线| 欧美国产禁国产网站cc| 日本黄色三级网站| 久久影院中文字幕| 色综合久久中文字幕综合网| 国产精品99精品一区二区三区∴| 红杏成人性视频免费看| 无线免费在线视频| 男女性杂交内射妇女bbwxz| 精品久久久中文字幕人妻| 鲁鲁狠狠狠7777一区二区| 欧美大片黄色| 国产精品一区二区电影| 亚洲成人精品电影在线观看| 国产欧美亚洲精品| 激情视频综合网| 亚洲第五色综合网| 中文字幕免费在线观看视频一区| 俺也去精品视频在线观看| 日韩欧美在线第一页| 被弄出白浆喷水了视频| 国产第一页精品| 亚洲欧美日本在线观看| 婷婷五月精品中文字幕| 亚洲的天堂在线中文字幕| 国产成人8x视频一区二区| 91一区二区三区在线观看| 欧美乱妇15p| 亚洲成人1区2区| 国产制服91一区二区三区制服| 色国产精品一区在线观看| 亚洲精品v天堂中文字幕| 久久综合一区二区| 一区二区成人免费视频| 在线免费av资源| 中文字幕日韩精品一区二区| 亚洲va国产va欧美va观看|