国产激情自拍_国产9色视频_丁香花在线电影小说观看 _久久久久国产精品嫩草影院

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

hdu1044【bfs+dfs】

2019-11-10 20:21:18
字體:
來源:轉載
供稿:網友

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"); }}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
国产激情自拍_国产9色视频_丁香花在线电影小说观看 _久久久久国产精品嫩草影院
天天操天天操一操| www.狠狠操| 狠狠插狠狠操| 久久香蕉av| 国产一区二区三区美女秒播 | 在线观看av中文| 亚洲综合在线免费| wwwww亚洲| 国产精品一区在线看| www在线视频| 国产乱码在线| 在线三级中文| 国产在线精品一区二区不卡| 国产免费一级| 99久久精品免费观看国产| www.超级碰| 国产青青草在线| 男人天堂99| 97最新国自产拍视频在线完整在线看 | 四虎精品视频| 国产精品一区牛牛影视| 99视频免费| 国产高清免费av在线| 日本三级在线视频| 国产精品伦一区二区三区级视频频 | 国产亚洲依依| 99中文字幕一区| 欧美精品se| 91高清国产| 国产欧美日韩专区| 国产免费视频在线| 欧美亚洲天堂| 中文字幕免费中文| jlzzjlzz欧美| 国产精品入口麻豆免费| 噜噜噜噜噜在线视频| 在线视频观看亚洲| 精品视频二区三区| 国产精品xxx电影| 最新天堂资源在线资源| 日韩欧美中文字幕不卡| 91午夜在线| 国产精品国精产品一二| 国产一区在线视频观看| 香蕉视频在线看| av福利在线| 在线中文字幕av| 国产精品xxx电影| 国产精品666| 国产二区三区四区| 中文在线官网天堂| 亚洲欧洲成人| 羞羞视频在线免费看| 亚洲人成影院在线| www.99av| 国产一区二区三区美女秒播| 操操操综合网| 国产精品综合久久久久| 欧美日韩亚洲第一页| 免费a在线看| 国产蜜臀av在线播放| 国内自拍视频在线观看| 最近免费中文字幕大全免费第三页| 国产精品一区在线看| 国产成人午夜| 欧美性猛交xxxxbbbb| 成人精品福利| 国产一级影片| 亚洲精品视频区| 国产免费av高清在线| 97一区二区三区| 超碰免费在线观看| 国产二区在线播放| 99免费视频| 国产美女视频一区二区三区| 国产三级在线免费观看| 欧美性猛交p30| 国产porny蝌蚪视频| 天天草天天爽| 国产成人亚洲精品播放器下载| 日本调教视频在线观看| 中文字幕视频在线| 日本欧洲一区| 在线观看中文字幕一区| 最近免费中文字幕大全免费第三页| 18av在线播放| 国产精品外围在线观看| 青青青青在线| 国产精品第八页| 国产在线激情视频| 国产原创在线播放| heisi视频网在线观看| 精品成人免费自拍视频| 国产免费av高清在线| www免费在线观看| 伊人福利在线| 99久热re在线精彩视频| 最新中文字幕在线视频| 国产永久免费高清在线观看视频| 羞羞视频在线观看免费| 国产精品yjizz视频网一二区 | 丁香花在线电影| 日本调教视频在线观看| 精品视频麻豆入口| 国产精品视频一区麻豆| 国产青草视频在线观看视频| 国产日本在线视频| 国产精品186在线观看在线播放 | 99色在线视频| 天天av综合网| 国产午夜电影| 国产视频青青| 精品国产美女福利到在线不卡| 69视频在线观看| 四虎国产精品永久在线| 日本三级在线视频| 国产理论片免费观看| 国产福利小视频在线观看| 国产va在线观看| 亚洲精品少妇久久久久久| 亚洲天堂久久久| 欧美日韩在线精品成人综合网| 免费精品国产自产拍观看| 久草福利资源在线视频| 最近免费中文字幕在线第一页| 国产性一级片| 国产变态拳头交视频一区二区 | 午夜在线不卡| 国产免费视频| 91午夜在线| 青青青青在线| 96久久久久久| 久热中文字幕| 伊人福利在线| 国产精品扒开做爽爽爽的视频| 精品51国产黑色丝袜高跟鞋| a级片国产精品自在拍在线播放| 国产美女福利在线| 91在线视频免费看| av网站大全在线观看| 国产在线一二三区| 99中文字幕一区| 国产在线拍揄自揄拍视频| 国产香蕉尹人视频在线| 日本动漫同人动漫在线观看| 国产精品入口麻豆完整版| 美女免费视频黄| eeuss影院网站免费观看| 国产网站免费看| 日本啊v在线| av大片在线| 精精国产xxxx视频在线中文版| 日韩av成人| 狠狠操视频网| 日本不卡视频一区二区| 国产95在线|亚洲| 中文字幕在线永久在线视频| 美女被人操视频在线观看| 亚洲成av人影片在线观看| 在线视频婷婷| 一本大道五月香蕉| 中文av字幕| 伊人影院在线视频| 在线三级av| 亚洲成人av在线影院| 中文字幕4区| 一本久久精品| 欧美日韩亚洲国内综合网| eeuss影院在线| a级在线观看| av片在线观看永久免费| 一本久久精品| 日本成人免费网站| 狠狠干五月天| 综合激情亚洲| 中文字幕2019第三页| 亚洲天堂二区| 九九免费视频| 国产精品久久久久白浆| 国产啊啊啊视频在线观看| 在线观看精品一区二区三区| 亚洲人成影院在线| 免费观看久久久久| 九九色在线观看| 最新av中文字幕| 国产激情网址| v天堂福利视频在线观看| 99热最新网址| 香蕉视频网站在线观看| 黄色av网址在线免费观看| 国产精品久久久高清免费| 日本三级在线视频| 国产污污在线观看| av在线播放网| 国产网站免费观看| 波多野结衣中文字幕久久| 国产一区二区影视| 午夜在线观看91| 国产午夜在线视频| 亚洲永久免费网站|