At the first I think it's a dynamic programming . But the truth hurt my immature soul.It's Dijkstra.At last,I want to say,The input so disgusting.
The portal:http://acm.hdu.edu.cn/showproblem.php?pid=2722
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#define MAXN 1005
using namespace std;
int cost[MAXN][MAXN];
int mincost[MAXN];
bool vis[MAXN];
int pre[MAXN];
const int INF = 0x3f3f3f3f;
int n,m;
void Dijkstra(int nn,int beg){
memset(vis,0,sizeof(vis));
memset(pre,-1,sizeof(pre));
memset(mincost,0x3f,sizeof(mincost));
mincost[beg] = 0;
for(int j=1;j<=nn;j++){
int Min = INF,k = -1;
for(int i=1;i<=nn;i++){
if(!vis[i]&&mincost[i]<Min){
Min = mincost[i];
k = i;
}
}
if(k==-1)break;
vis[k] = true;
for(int i=1;i<=nn;i++){
if(!vis[i]&&mincost[k]+cost[k][i]<mincost[i]){
mincost[i] = mincost[k] + cost[k][i];
pre[i] = k;
}
}
}
}
void Solve(){
Dijkstra((n+1)*(m+1),1);
if(mincost[(n+1)*(m+1)]==INF){
puts("Holiday");
}
else
printf("%d blips\n",mincost[(n+1)*(m+1)]);
}
void Input(){
int tempa,i,j;
char tempc;
while(scanf("%d %d",&n,&m),n+m){
//printf("%d %d\n",n,m);
memset(cost,0x3f,sizeof(cost));
for(i=1;i<=2*n+1;i++){
if(i&1){
for(j=1;j<=m;j++){
scanf("%d %c",&tempa,&tempc);
//printf("%d %c ",tempa,tempc);
if(tempa==0){
continue;
}
cost[(i/2)*(m+1)+j][(i/2)*(m+1)+j+1] = 2520/tempa;
cost[(i/2)*(m+1)+j+1][(i/2)*(m+1)+j] = 2520/tempa;
if(tempc=='<')cost[(i/2)*(m+1)+j][(i/2)*(m+1)+j+1] = INF;
if(tempc=='>')cost[(i/2)*(m+1)+j+1][(i/2)*(m+1)+j] = INF;
}
}
else {
for(j=1;j<=m+1;j++){
scanf("%d %c",&tempa,&tempc);
//printf("%d %c ",tempa,tempc);
if(tempa==0){
continue;
}
cost[(i/2-1)*(m+1)+j][(i/2)*(m+1)+j] = 2520/tempa;
cost[(i/2)*(m+1)+j][(i/2-1)*(m+1)+j] = 2520/tempa;
if(tempc=='^')cost[(i/2-1)*(m+1)+j][(i/2)*(m+1)+j] = INF;
if(tempc=='v')cost[(i/2)*(m+1)+j][(i/2-1)*(m+1)+j] = INF;
}
}
}
Solve();
}
}
int main(void){
freopen("2722.in","r",stdin);
Input();
return 0;
}