DP+DFS,记忆化搜索,典型的用空间换时间。View Code #include<stdio.h>#include<string.h>int dp[101][101],h[101][101];int dir[4][2]={1,0,-1,0,0,1,0,-1};int m,n;int dfs(int x,int y){ if(dp[x][y])return dp[x][y]; int i,temp; for(i=0;i<4;i++) { int fx=x+dir[i][0]; int fy=y+dir[i][1]; if(fx>... Read More
posted @ 2012-06-02 22:34
To be an ACMan
Views(178)
Comments(0)
Diggs(0)
经典三维BFS,此题用DFS会超时,用BFS不剪枝也会超时,其实跟二维的BFS没什么区别View Code #include<stdio.h>#define maxn 31struct node{ int x,y,z; int cnt;};const int dir[6][3]={{0,-1,0},{-1,0,0},{0,1,0},{1,0,0},{0,0,-1},{0,0,1}};int map[maxn][maxn][maxn];int a,b,c,t;int bfs(){ node q[maxn*maxn*maxn]; node n,p; int i,rea... Read More
posted @ 2012-06-02 20:41
To be an ACMan
Views(177)
Comments(0)
Diggs(0)

浙公网安备 33010602011771号