• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆 - 97, 文章 - 22, 評論 - 81, 引用 - 0
            數據加載中……

            Pku 2662 A Walk Through the Forest && HDU 1428 漫步校園 (bfs + dfs)

            首先從終點bfs,保存每一個節點到終點的最短路徑,然后從起點dfs,記憶化,如果滿足題目給定的拓撲序就加上從那個點到終點的路徑數。所謂滿足拓撲序就是題目所給定的taking a path from A to B to be progress if there exists a route from B to his home that is shorter than any possible route from A,這句話仔細讀上幾十遍就能明白題目意圖了。

            漫步校園
            代碼:

            #include <iostream>
            #include 
            <queue>
            using namespace std;

            int dir[4][2= {{01}{0-1}{10}{-10}};
            struct point {
                
            int x;
                
            int y;
                
            int time;

                
            bool friend operator < (point a, point b) {
                    
            return a.time > b.time;
                }


            }
            temp, tt;

            priority_queue 
            < point > q;
            int hash[51][51], map[51][51];
            __int64 dp[
            51][51];
            int n;

            __int64 dfs(
            int x, int y) {
                
                
            int i;
                
            int tx, ty;
                __int64 sum 
            = 0;

                
            if(x == n && y == n)
                    
            return 1;

                
            for(i = 0; i < 4; i++{
                    tx 
            = x + dir[i][0];
                    ty 
            = y + dir[i][1];
                    
            if(tx < 1 || ty < 1 || tx > n || ty > n)
                        
            continue;
                    
            if(hash[x][y] > hash[tx][ty]) {
                        
            if(dp[tx][ty] == -1{
                            dp[tx][ty] 
            = dfs(tx, ty);
                        }

                        sum 
            += dp[tx][ty];
                    }

                }


                
            return sum;
            }

            int main() {
                
            int i, j;
                
            while(scanf("%d"&n) != EOF) {

                    
            for(i = 1; i <= n; i++{
                        
            for(j = 1; j <= n; j++{
                            scanf(
            "%d"&map[i][j]);
                        }

                    }

                    temp.x 
            = n;
                    temp.y 
            = n;
                    temp.time 
            = map[n][n];
                    memset(hash, 
            -1sizeof(hash));
                    hash[n][n] 
            = map[n][n];
                    
            while(!q.empty())
                        q.pop();

                    q.push( temp );

                    
            while(!q.empty()) {
                        temp 
            = q.top();
                        q.pop();
                        
            for(i = 0; i < 4; i++{
                            tt.x 
            = temp.x + dir[i][0];
                            tt.y 
            = temp.y + dir[i][1];
                            
            if(tt.x < 1 || tt.y < 1 || tt.x > n || tt.y > n)
                                
            continue;
                            tt.time 
            = temp.time + map[tt.x][tt.y];
                            
                            
            if(hash[ tt.x ][ tt.y ] == -1 || tt.time < hash[ tt.x ][ tt.y ]) {
                                hash[ tt.x ][ tt.y ] 
            = tt.time;
                                q.push( tt );
                            }

                        }

                    }


                    memset(dp, 
            -1sizeof(dp));

                    dp[
            1][1= dfs(11);
                    printf(
            "%I64d\n", dp[1][1]);
                }

                
            return 0;
            }

            posted on 2009-03-09 19:12 英雄哪里出來 閱讀(718) 評論(2)  編輯 收藏 引用 所屬分類: ACM

            評論

            # re: Pku 2662 A Walk Through the Forest && HDU 1428 漫步校園 (bfs + dfs)  回復  更多評論   

            taking a path from A to B to be progress if there exists a route from B to his home that is shorter than any possible route from A

            這句話就是說有拓撲序了,啊…… 太強了,Orz!!
            我都不知道是什么意思!
            2009-12-03 10:28 | huangzhifei

            # re: Pku 2662 A Walk Through the Forest && HDU 1428 漫步校園 (bfs + dfs)  回復  更多評論   

            我就是想過不用DFS,用BFS去遍歷所獲得的耗時表,為什么不行呢?
            詳細的情況:http://acm.hdu.edu.cn/forum/read.php?tid=17192
            希望你能幫我看看,感激不盡~~
            2010-07-23 11:05 | Geek.tan
            国产成年无码久久久免费| 99国产欧美久久久精品蜜芽 | 一本色道久久88精品综合| 久久无码专区国产精品发布| 精品国产乱码久久久久久人妻 | 少妇人妻综合久久中文字幕| 国产69精品久久久久APP下载| 99久久国产综合精品女同图片| 精品国产一区二区三区久久久狼| 久久青草国产手机看片福利盒子| 久久婷婷人人澡人人| 亚洲人成网亚洲欧洲无码久久| 国产精品久久波多野结衣| 日本亚洲色大成网站WWW久久| 久久综合噜噜激激的五月天| 久久人人爽人人精品视频| 91精品国产综合久久婷婷| 久久无码高潮喷水| 国产精品成人久久久久三级午夜电影| 少妇人妻综合久久中文字幕| 伊人色综合久久| 日本强好片久久久久久AAA| 久久久久久无码国产精品中文字幕 | 久久久久久综合一区中文字幕| yy6080久久| 久久久WWW成人| 热re99久久精品国产99热| 久久综合给久久狠狠97色| 97精品国产97久久久久久免费| 久久99精品久久久久久噜噜| 秋霞久久国产精品电影院| 97久久超碰国产精品旧版| 久久久久久午夜精品| 久久男人中文字幕资源站| 久久久久国产精品麻豆AR影院| 精品精品国产自在久久高清| 国产精品久久久久9999| 国产精品久久久久影院嫩草| 国产午夜精品理论片久久影视| 久久久国产乱子伦精品作者| 久久夜色精品国产噜噜亚洲AV|