• <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 糯米 閱讀(403) 評論(0)  編輯 收藏 引用 所屬分類: POJ

            亚洲国产精品无码久久| 久久综合九色综合网站| 久久久国产精品网站| 国产精品久久久久久| 久久伊人色| 久久综合狠狠综合久久激情 | 久久久久国产一级毛片高清板| 77777亚洲午夜久久多人| 久久久精品一区二区三区| 久久天天躁狠狠躁夜夜2020一 | 久久久久无码精品国产| 伊人久久无码精品中文字幕| 中文精品久久久久国产网址| 国产精品久久新婚兰兰| 久久天天躁狠狠躁夜夜不卡| 成人国内精品久久久久影院| 中文精品久久久久人妻不卡| 亚洲人成网亚洲欧洲无码久久| 久久国产成人午夜AV影院| 国产亚洲美女精品久久久| 国产美女久久精品香蕉69| 无码人妻久久一区二区三区免费 | 日韩人妻无码一区二区三区久久| 狠狠久久综合| 久久精品国产亚洲AV忘忧草18| 亚洲七七久久精品中文国产| 青青热久久国产久精品 | 久久综合精品国产一区二区三区| 久久婷婷五月综合色99啪ak| 久久久久久久综合狠狠综合| 久久精品中文字幕无码绿巨人 | 精品久久久久成人码免费动漫 | 国产成年无码久久久久毛片| 色婷婷狠狠久久综合五月| 久久无码专区国产精品发布| 老司机国内精品久久久久| 国内精品久久国产| 久久婷婷午色综合夜啪| 久久激情亚洲精品无码?V| 久久99国产精一区二区三区| 久久精品国产亚洲av麻豆图片|