H-fire DrillTime
limit:3000MS
Memory Limit:0KB
64bit IO Format:%lld &%lluSubmit Status Practice uvalive 5066
Description
Joko is taking part in a fire drill which are held by the Jakarta fire Department to recruit new firemen. The drill is on rescuing volunteers (who act as unconscious people) trapped in a building in a limited time. The building has several floors, and the volunteers is scattered throughout the building. Each volunteer have points assigned to her. The fireman candidate should rescue volunteers through carrying them to the exit. The candidate would earn the assigned points for each volunteer he rescued.
Each floor of a building can is seen as a grid of cells. Each cell can is an obstacle, an empty space, a stair or an entry/exit point.
A candidate starts at the entry point which exists is at one single cell in the first floor of the building. The candidate can move to any adjacent non-obstacle cells (north, south, west or east) or climb up or down a stair in 1 se Cond. The movement slows down to 2 seconds when the candidate carries a volunteer. When a candidate finds a volunteer, he is decide to rescue she or not, but if he decides to rescue her, he had to carry H Er back to the exit without stopping. He can only be carry at the most one volunteer at a time.
Joko has the floor plan of the the Test building. Help him plan his moves, so he can get the highest possible score.
Input
The first line of input contains an integer T ( T ) denoting The number of case. Each case has five integers L (1 L ), H (1 H ), W (1 W 100), Span class= "math" > N (1 N ) and S (1 S ) denoting the number of floors, height and weight of each floor, the number of Unco Nscious people, and the given time respectively.
The next L blocks describe the map of each floor from the 1st floor to the L -th floor respectively. Each floor consists of H lines each contains W characters. Characters, appear in all floor is:
- ' S ': The starting point, also serves as the exit point. There'll is only one starting/exit point and it'll appear in the first floor.
- ' X ': obstacle, cell that cannot is visited (wall, fire, etc).
- ' U ': Stair that connect to the upper floor. There'll be a ' D ' character at the same place in the upper level. This character won't appear in the highest level of the building.
- ' D ': Stair that connect to the lower floor. There'll be a ' U ' character at the same-the lower level. This character won't appear in the lowest level of the building.
- ' . ": Empty space, cell that can is visited.
The next N lines each contains four integers fi(1FiL), Ri< c9> (1RIH), CI(1CiW), pI(1 pI1, denoting the location of each volunteer (floor, row, column) and the "point" assigned to this volunteer respectively. You can assume this each volunteer'll be located in empty space and no, and no, volunteer occupy the same location.
Output
For each case, output in a line a single integer the highest point so he can earn by rescuing unconscious people within The given time.
Sample Input
2 3 3 5 3 XXXXX X.. UX xsxxx XXXXX XU. DX XXXXX XXXXX XD. X XXXXX 1 2 3 10 3 2 3 50 3 2 4 60 2 2 6 4 27 ... S.. U ...... D.. 1 2 3 20 1 2 5 50 1 2 6 50 2 1 1 90
Sample Output
110 100
#include <stdio.h>#include<string.h>#include<queue>using namespacestd; structNode {intx,y,z,t; }; Const intd[4][3]= {{0,1,0},{0,0,1},{0,-1,0},{0,0,-1}}; Charss[ One][101][101]; intpp[ One][101][101];inth,w,l; ints,v[101],p[101],f[10001]; BOOLzg[ One][101][101]; Charsss[102];node r[100005];intGgg,gg;BOOLCheckintZintXinty) {if(x>-1&&y>-1&&z>-1&&zL)return 1; return 0; } voidBFS (intXxintYyintZzintTT) { inti; intx3,y3,z3; if(ss[zz][xx][yy]=='P') {P[pp[zz][xx][yy]]=tt*3; } if(ss[zz][xx][yy]=='U'&&zg[zz+1][xx][yy]==0) {Zg[zz+1][xx][yy]=1; r[ggg].x=xx; R[ggg].y=yy; R[ggg].z=zz+1; R[GGG++].t=tt+1; } if(ss[zz][xx][yy]=='D'&&zg[zz-1][xx][yy]==0) {Zg[zz-1][xx][yy]=1; r[ggg].x=xx; R[ggg].y=yy; R[ggg].z=zz-1; R[GGG++].t=tt+1; } for(i=0;i<4; i++) {x3=xx+d[i][1]; Y3=yy+d[i][2]; Z3=ZZ; if(Check (Z3,X3,Y3) &&ss[z3][x3][y3]!='X'&&zg[z3][x3][y3]==0) {Zg[z3][x3][y3]=1; r[ggg].x=X3; R[ggg].y=Y3; R[ggg].z=Z3; R[GGG++].t=tt+1; } } ++GG; if(gg!=GGG) BFS (r[gg].x,r[gg].y,r[gg].z,r[gg].t);}intMain () {intt,n,x,y,z,i,j,t; intEx,ey; scanf ("%d",&T); while(t--) {GGG=0; gg=-1; scanf ("%d%d%d%d%d",&h,&w,&l,&n,&S); for(i=0; i) { for(j=0; j<w;j++) {scanf ("%s", SSS); for(t=0; t<l;t++) {Zg[i][j][t]=0; Ss[i][j][t]=Sss[t]; if(sss[t]=='S') {ex=j,ey=T; } } } } for(intI=0; i<n; i++) {scanf ("%d%d%d%d",&z,&x,&y,&V[i]); Ss[z-1][x-1][y-1]='P'; Pp[z-1][x-1][y-1]=i; P[i]=s+3; } zg[0][ex][ey]=1; BFS (Ex,ey,0,0); //01 BackpackMemset (F,0,sizeof(f)); for(i=0; i<n;i++) { for(j=s;j>=p[i];j--) {F[j]=max (f[j],f[j-p[i]]+V[i]); }} printf ("%d\n", F[s]); } return 0; }
Uvalive 5066 fire Drill bfs+ Backpack