HDU 1044

来源:互联网 发布:网页游戏劫持数据 编辑:程序博客网 时间:2024/06/16 23:08

Collect More Jewels

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6673    Accepted Submission(s): 1546


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
34 4 2 2100 200*****@A**B<*****4 4 1 2100 200*****@A**B<*****12 5 13 2100 200*************B.........**.********.**@...A....<*************
 

Sample Output
Case 1:The best score is 200.Case 2:ImpossibleCase 3:The best score is 300.
 

Source
Asia 2005, Hangzhou (Mainland China), Preliminary
 

Recommend
JGShining   |   We have carefully selected several similar problems for you:  1043 1175 1401 1067 1254 

 



有宝物的,,在一定时间内能拿最多价值的宝物并且走出去。

#include <bits/stdc++.h>#include <queue>using namespace std;#define pb push_back#define mp make_pair#define all(x) (x).begin(),(x).end()#define fi first#define se second#define SZ(x) ((int)(x).size())typedef vector<int> VI;typedef long long LL;typedef pair<int,int> PII;typedef pair<double,double> PDD;const int N=1e3+10;const double eps=1e-9;char mat[100][100];int vis[55][55][1030];   //2^10;int val[15];int dir[4][2]= {0,1,0,-1,1,0,-1,0};int n,m;struct node{    int bao;    int x,y;    int step;};bool check(int x,int y){    if(x>=0 &&x<n  &&y>=0 &&y<m &&mat[x][y]!='*')        return 1;    else        return  0;}void bfs(int x1,int y1,int x2,int y2,int time){    int ans=-222;    queue<node>q;    while(!q.empty())        q.pop();    node st,ed;    st.x=x1;    st.y=y1;    st.bao=st.step=0;    q.push(st);    memset(vis,0,sizeof(vis));    vis[x1][y1][0]=1;    while(!q.empty())    {        st=q.front();        q.pop();        for(int i=0; i<4; i++)        {            ed.x=st.x+dir[i][0];            ed.y=st.y+dir[i][1];            if(check(ed.x,ed.y))            {                if(mat[ed.x][ed.y]!='.')                    ed.bao=(st.bao|(1<<(mat[ed.x][ed.y]-'A')));                else                    ed.bao=st.bao;                if(vis[ed.x][ed.y][ed.bao])                    continue;                vis[ed.x][ed.y][ed.bao]=1;                ed.step=st.step+1;             //   cout<<st.x<<"   "<<st.y<<"------>>"<<ed.x<<"  "<<ed.y<<endl;                if(ed.x==x2 &&ed.y==y2)                {                    int res=0;                    for(int j=0,kk=1; j<10; j++,kk*=2)                        if(kk&ed.bao)                            res+=val[j];                    ans=max(ans,res);                }                if(ed.step==time)                    continue;                q.push(ed);            }        }    }    if(ans==-222)        printf("Impossible\n");    else        printf("The best score is %d.\n",ans);}int main(){    int T;    scanf("%d",&T);    int cass=0;    while(T--)    {        int t,k;        int i,j;        cin>>m>>n>>t>>k;        for(i=0; i<k; i++)            cin>>val[i];        for(i=0; i<n; i++)            cin>>mat[i];        int stx,sty;        int edx,edy;        for(i=0; i<n; i++)            for(j=0; j<m; j++)            {                if(mat[i][j]=='@')                {                    stx=i;                    sty=j;                    mat[i][j]='.';                }                else if(mat[i][j]=='<')                {                    edx=i;                    edy=j;                    mat[i][j]='.';                }            }        printf("Case %d:\n",++cass);        bfs(stx,sty,edx,edy,t);        if(T!=0)            printf("\n");    }    return 0;}

0 0
原创粉丝点击