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

            亚洲精品午夜国产VA久久成人| 91久久香蕉国产熟女线看| 国产精品99久久久精品无码| 一本大道久久香蕉成人网| 亚洲精品无码久久久久久| 久久久久夜夜夜精品国产| 欧美精品福利视频一区二区三区久久久精品 | 亚洲精品NV久久久久久久久久 | 久久精品一区二区三区不卡| 久久国产精品一区二区| 亚洲欧洲精品成人久久曰影片| 久久99精品久久只有精品| 久久99精品国产99久久6| 欧美亚洲色综久久精品国产| 久久久久这里只有精品| 国内精品久久久久影院一蜜桃| 狠狠色丁香婷婷综合久久来来去 | 欧美精品一区二区久久| 成人综合伊人五月婷久久| 无码乱码观看精品久久| 国产99久久九九精品无码| 色欲综合久久躁天天躁蜜桃| 精品乱码久久久久久夜夜嗨| 99久久精品国内| 少妇精品久久久一区二区三区| 中文字幕无码av激情不卡久久| 91久久香蕉国产熟女线看| 久久99国产精品一区二区| 日本久久久久亚洲中字幕| 囯产极品美女高潮无套久久久| 人妻无码精品久久亚瑟影视| 大美女久久久久久j久久| 国产精品欧美久久久天天影视| 久久久久亚洲av无码专区| 久久无码AV中文出轨人妻| 波多野结衣久久| 亚洲中文字幕无码久久精品1 | 久久黄视频| 国产Av激情久久无码天堂| 久久亚洲中文字幕精品有坂深雪| 久久亚洲AV成人无码软件|