• <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
            国产成人精品白浆久久69| 人人狠狠综合88综合久久| 久久久久久国产精品无码下载| 久久夜色精品国产噜噜亚洲a | 精品久久8x国产免费观看| 久久成人国产精品二三区| 欧美成a人片免费看久久| 伊人久久精品无码av一区| 欧美喷潮久久久XXXXx| 久久精品中文字幕第23页| 亚洲精品高清一二区久久| 99久久精品免费看国产一区二区三区| 国产精品久久久久天天影视| 久久综合久久鬼色| 久久99精品国产自在现线小黄鸭| 精品一久久香蕉国产线看播放| 色妞色综合久久夜夜| 色婷婷噜噜久久国产精品12p | 国产A级毛片久久久精品毛片| 久久久久亚洲av成人网人人软件 | 久久婷婷人人澡人人爽人人爱| 久久青青草原综合伊人| 影音先锋女人AV鲁色资源网久久| 狠狠综合久久综合中文88| 国产精品久久久久…| 久久综合亚洲色一区二区三区| 久久精品国产一区二区| 久久青青草原国产精品免费| avtt天堂网久久精品| 久久婷婷国产综合精品| 日韩精品久久无码中文字幕| 亚洲国产成人精品91久久久| 精品久久久久久无码人妻热| 丁香狠狠色婷婷久久综合| 97久久香蕉国产线看观看| 午夜精品久久久久久久久| 无码AV波多野结衣久久| 亚洲精品无码久久一线| 久久天天躁狠狠躁夜夜躁2014| 亚洲精品美女久久久久99小说| 婷婷久久综合九色综合九七|