• <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>

            糯米

            TI DaVinci, gstreamer, ffmpeg
            隨筆 - 167, 文章 - 0, 評論 - 47, 引用 - 0
            數據加載中……

            POJ 2111 Millenium Leapcow 動態規劃

            思路:

            先按棋盤上的值從大到小排序。
            然后先解決值大的,再解決值小的。
            注意路徑的比較。應該很容易WA的。

            #include <stdio.h>
            #include 
            <algorithm>

            using namespace std;

            #define MAX_N 512

            struct seq_node {
                
            short y, x;
            }
            ;
            struct map_node {
                
            int val, cnt;
                
            struct map_node *pre;
            }
            ;
            struct map_node map[MAX_N][MAX_N], *ans;
            struct seq_node seq[MAX_N*MAX_N];
            int N;

            int cmp_seq(const void *a, const void *b)
            {
                
            return    map[((struct seq_node *)a)->y][((struct seq_node *)a)->x].val - 
                        map[((
            struct seq_node *)b)->y][((struct seq_node *)b)->x].val;
            }


            inline 
            int cmp_path(struct map_node *a, struct map_node *b)
            {
                
            while (a && b) {
                    
            if (a->val != b->val)
                        
            return a->val - b->val;
                    a 
            = a->pre;
                    b 
            = b->pre;
                }

                
            return 0;
            }


            inline 
            void update(struct map_node *a, int y2, int x2)
            {
                
            struct map_node *= &map[y2][x2];

                
            if (y2 < 0 || y2 >= N || x2 < 0 || x2 >= N)
                    
            return ;    
                
            if (b->val > a->val && 
                    (b
            ->cnt > a->cnt || b->cnt == a->cnt && cmp_path(b, a->pre) < 0)
                    ) 
                
            {
                    a
            ->cnt = b->cnt;
                    a
            ->pre = b;
                }

            }


            int main()
            {
                
            int x, y, i;
                
            struct seq_node *t;
                
            struct map_node *m;

                freopen(
            "e:\\test\\in.txt""r", stdin);

                scanf(
            "%d"&N);
                i 
            = 0;
                
            for (y = 0; y < N; y++{
                    
            for (x = 0; x < N; x++{
                        scanf(
            "%d"&map[y][x].val);
                        seq[i].y 
            = y;
                        seq[i].x 
            = x;
                        i
            ++;
                    }

                }

                qsort(seq, N
            *N, sizeof(seq[0]), cmp_seq);

                
            for (t = &seq[N*- 1]; t >= seq; t--{
                    m 
            = &map[t->y][t->x];
                    update(m, t
            ->- 2, t->+ 1);
                    update(m, t
            ->+ 2, t->+ 1);
                    update(m, t
            ->- 2, t->- 1);
                    update(m, t
            ->+ 2, t->- 1);
                    update(m, t
            ->- 1, t->+ 2);
                    update(m, t
            ->+ 1, t->+ 2);
                    update(m, t
            ->- 1, t->- 2);
                    update(m, t
            ->+ 1, t->- 2);
                    m
            ->cnt++;
                    
            if ((!ans || m->cnt > ans->cnt) ||
                        (m
            ->cnt == ans->cnt && cmp_path(m, ans) < 0)
                        ) 
                        ans 
            = m;
                }


                printf(
            "%d\n", ans->cnt);
                
            while (ans) {
                    printf(
            "%d\n", ans->val);
                    ans 
            = ans->pre;
                }


                
            return 0;
            }

            posted on 2010-04-27 14:14 糯米 閱讀(406) 評論(0)  編輯 收藏 引用 所屬分類: POJ

            久久久久国产| 精品国产婷婷久久久| 熟妇人妻久久中文字幕| 久久精品久久久久观看99水蜜桃| 尹人香蕉久久99天天拍| 久久久精品人妻一区二区三区蜜桃| 精品一区二区久久久久久久网站| 久久激情亚洲精品无码?V| 国产69精品久久久久9999APGF| 久久久久久久尹人综合网亚洲 | 久久超碰97人人做人人爱| 色综合色天天久久婷婷基地| 国产精品久久久久久久久软件| 99久久99这里只有免费费精品| 久久久久国产日韩精品网站| 国产精品女同久久久久电影院| 伊人久久五月天| 久久艹国产| 天天久久狠狠色综合| 久久综合国产乱子伦精品免费| 日韩美女18网站久久精品 | 久久久久综合国产欧美一区二区 | 91精品婷婷国产综合久久| 亚洲级αV无码毛片久久精品| 久久无码人妻精品一区二区三区| 97久久国产亚洲精品超碰热 | 亚洲AV无码久久| 日韩人妻无码一区二区三区久久99| 草草久久久无码国产专区| 99久久免费国产特黄| 久久综合给合久久国产免费| 狠狠色婷婷久久综合频道日韩| 亚洲人成电影网站久久| 色婷婷综合久久久久中文字幕 | 国产精品免费久久| 国产精久久一区二区三区| 2020最新久久久视精品爱| yellow中文字幕久久网| 久久久精品久久久久久 | 国产三级久久久精品麻豆三级| 人妻精品久久久久中文字幕一冢本|