http://oj.ecustacm.cn/problem.php?id=1455
s数值不能设为)0x3f,如果设为它,机器跑不出来,具体我也不知道为什么
再一个,这个题dfs跑不出来,所以提交答案
dfs
#include <bits/stdc++.h> using namespace std; char a; int mp[40][60]; int vis[40][60],step[40][60]; string ans; int s =9999999;// 0x3f; int v[10000]; int dp[4][2] ={{1,0},{0,-1},{0,1},{-1,0}}; int dir[4] = {'D','L','R','U'}; void dfs(int x,int y,int sp){ if(s < sp) return; if(x == 29 && y == 49){ if(s > sp){ s = sp; ans = ""; for(int i = 1; i < sp; i++) ans += dir[v[i]]; } return; } for(int i = 0; i < 4; i++){ int dx = x + dp[i][0]; int dy = y + dp[i][1]; if(dx < 0 || dx > 29 || dy < 0 || dy > 49) continue; if(vis[dx][dy] || mp[dx][dy]) continue; if(sp + 1 > step[dx][dy]) return; step[dx][dy] = sp + 1; vis[dx][dy] = 1; v[sp] = i; dfs(dx,dy,sp + 1); vis[dx][dy] = 0; } } int main(){ //freopen("in","r",stdin); ios::sync_with_stdio(0); memset(step,0x3f, sizeof(step)); for(int i = 0; i < 30; i++){ for(int j = 0; j < 50; j++){ cin >> a; mp[i][j] = a - '0'; } } vis[0][0] = 1; dfs(0,0,1); cout << ans << endl; //cout << "DDDDRRURRRRRRDRRRRDDDLDDRDDDDDDDDDDDDRDDRRRURRUURRDDDDRDRRRRRRDRRURRDDDRRRRUURUUUUUUULULLUUUURRRRUULLLUUUULLUUULUURRURRURURRRDDRRRRRDDRRDDLLLDDRRDDRDDLDDDLLDDLLLDLDDDLDDRRRRRRRRRDDDDDDRR"; return 0; }