• <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 英雄哪里出來 閱讀(710) 評論(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
            青青草国产精品久久| 区久久AAA片69亚洲| 久久亚洲精品中文字幕| 国产精品久久成人影院| segui久久国产精品| 久久精品一本到99热免费| 久久久久人妻一区精品色| 久久国产成人午夜aⅴ影院| 怡红院日本一道日本久久| 久久亚洲中文字幕精品一区四| 四虎影视久久久免费观看| 伊人久久久AV老熟妇色| 久久久久亚洲av毛片大| 国内精品久久久久久99蜜桃 | 欧美日韩精品久久久久| 成人资源影音先锋久久资源网| 久久精品无码一区二区三区日韩| 久久婷婷五月综合国产尤物app| 久久99精品国产一区二区三区| 日韩人妻无码一区二区三区久久99 | 青青草原1769久久免费播放| 久久久久久亚洲精品不卡| 久久狠狠高潮亚洲精品| 2021国产精品久久精品| 久久av高潮av无码av喷吹| 久久婷婷综合中文字幕| 久久成人国产精品| 久久久久亚洲AV片无码下载蜜桃| 久久精品无码一区二区三区日韩| AAA级久久久精品无码区| 久久精品天天中文字幕人妻| 亚洲人成网亚洲欧洲无码久久| 天天影视色香欲综合久久| 久久久WWW成人| 久久国产三级无码一区二区| 色噜噜狠狠先锋影音久久| 91久久精品无码一区二区毛片| 久久久久久久久久久久中文字幕| 97精品国产97久久久久久免费| 久久精品无码一区二区WWW| 伊人久久大香线蕉无码麻豆 |