• <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>
            隨筆 - 87  文章 - 279  trackbacks - 0
            <2025年5月>
            27282930123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567

            潛心看書研究!

            常用鏈接

            留言簿(19)

            隨筆分類(81)

            文章分類(89)

            相冊

            ACM OJ

            My friends

            搜索

            •  

            積分與排名

            • 積分 - 216603
            • 排名 - 117

            最新評論

            閱讀排行榜

            評論排行榜


            Always On the Run

            Time limit: 1 Seconds?? Memory limit: 32768K??
            Total Submit: 125?? Accepted Submit: 70??

            Screeching tires. Searching lights. Wailing sirens. Police cars everywhere. Trisha Quickfinger did it again! Stealing the `Mona Lisa' had been more difficult than planned, but being the world's best art thief means expecting the unexpected. So here she is, the wrapped frame tucked firmly under her arm, running to catch the northbound metro to Charles-de-Gaulle airport.

            But even more important than actually stealing the painting is to shake off the police that will soon be following her. Trisha's plan is simple: for several days she will be flying from one city to another, making one flight per day. When she is reasonably sure that the police has lost her trail, she will fly to Atlanta and meet her `customer' (known only as Mr. P.) to deliver the painting.

            Her plan is complicated by the fact that nowadays, even when you are stealing expensive art, you have to watch your spending budget. Trisha therefore wants to spend the least money possible on her escape flights. This is not easy, since airlines prices and flight availability vary from day to day. The price and availability of an airline connection depends on the two cities involved and the day of travel. Every pair of cities has a `flight schedule' which repeats every few days. The length of the period may be different for each pair of cities and for each direction.

            Although Trisha is a good at stealing paintings, she easily gets confused when booking airline flights. This is where you come in.


            Input

            The input contains the descriptions of several scenarios in which Trisha tries to escape. Every description starts with a line containing two integers n and k. n is the number of cities through which Trisha's escape may take her, and k is the number of flights she will take. The cities are numbered 1, 2, ..., n, where 1 is Paris, her starting point, and n is Atlanta, her final destination. The numbers will satisfy 2 <= n <= 10 and 1 <= k <= 1000.
            Next you are given n(n - 1) flight schedules, one per line, describing the connection between every possible pair of cities. The first n - 1 flight schedules correspond to the flights from city 1 to all other cities (2, 3, ..., n), the next n - 1 lines to those from city 2 to all others (1, 3, 4, ..., n), and so on.

            The description of the flight schedule itself starts with an integer d, the length of the period in days, with 1 <= d <= 30. Following this are d non-negative integers, representing the cost of the flight between the two cities on days 1, 2, ..., d. A cost of 0 means that there is no flight between the two cities on that day.

            So, for example, the flight schedule ``3 75 0 80'' means that on the first day the flight costs 75, on the second day there is no flight, on the third day it costs 80, and then the cycle repeats: on the fourth day the flight costs 75, there is no flight on the fifth day, etc.

            The input is terminated by a scenario having n = k = 0.


            Output

            For each scenario in the input, first output the number of the scenario, as shown in the sample output. If it is possible for Trisha to travel k days, starting in city 1, each day flying to a different city than the day before, and finally (after k days) arriving in city n, then print ``The best flight costs x.'', where x is the least amount that the k flights can cost.

            If it is not possible to travel in such a way, print ``No flight possible.''.

            Print a blank line after each scenario.


            Sample Input

            3 6
            2 130 150
            3 75 0 80
            7 120 110 0 100 110 120 0
            4 60 70 60 50
            3 0 135 140
            2 70 80
            2 3
            2 0 70
            1 80
            0 0


            Sample Output

            Scenario #1
            The best flight costs 460.

            Scenario #2
            No flight possible.

            #include?<iostream>
            using?namespace?std;

            const?int?MAXN?=?11;
            const?int?MAXM?=?1001;
            const?int?INF?=??2000000000;

            int?n,?m;
            int?a[MAXN][MAXN][MAXM];
            int?d[MAXM][MAXN];
            int?num[MAXN][MAXN];

            int?main()
            {
            ????
            int?i,?j,?k,?l;
            ????
            int?t,?t1;
            ????
            int?tmp?=?0;
            ????
            while?(scanf("%d%d",?&n,?&m)?!=?EOF)?{
            ????????
            if?(n?==?0?&&?m?==?0)?break;
            ????????memset(a,?
            0,?sizeof(a));
            ????????
            for?(i=1;?i<=n;?i++)?{
            ????????????
            for?(j=1;?j<=n;?j++)?{
            ????????????????
            if?(i?!=?j)?{
            ????????????????????scanf(
            "%d",?&num[i][j]);
            ????????????????????
            for?(k=1;?k<=num[i][j];?k++)?{
            ????????????????????????scanf(
            "%d",?&a[i][j][k]);
            ????????????????????}

            ????????????????}

            ????????????}

            ????????}

            ????????
            for?(i=1;?i<=m;?i++)?{
            ????????????
            for?(j=1;?j<=n;?j++)?{
            ????????????????d[i][j]?
            =?INF;
            ????????????}

            ????????}

            ????????
            for?(j=1;?j<=n;?j++)?{
            ????????????
            if?(a[1][j][1]?>?0)?{
            ????????????????d[
            1][j]?=?a[1][j][1];
            ????????????}

            ????????}

            ????????
            for?(i=2;?i<=m;?i++)?{
            ????????????
            for?(j=1;?j<=n;?j++)?{
            ????????????????t?
            =?INF;
            ????????????????
            for?(k=1;?k<=n;?k++)?{
            ????????????????????
            if?(k?==?j)?continue;
            ????????????????????t1?
            =?i?%?num[k][j]?>?0???i?%?num[k][j]?:?num[k][j];
            ????????????????????
            if?(a[k][j][t1]?>?0?&&?t?>?d[i-1][k]?+?a[k][j][t1])?{
            ????????????????????????t?
            =?d[i-1][k]?+?a[k][j][t1];
            ????????????????????}

            ????????????????}

            ????????????????d[i][j]?
            =?t;
            ????????????}

            ????????}

            ????????printf(
            "Scenario?#%d\n",?++tmp);
            ????????
            if?(d[m][n]?!=?INF)?{
            ????????????printf(
            "The?best?flight?costs?%d.\n\n",?d[m][n]);
            ????????}
            ?else?{
            ????????????printf(
            "No?flight?possible.\n\n");
            ????????}

            ????}

            ????system(
            "pause");
            ????
            return?0;
            }

            posted on 2006-10-12 00:41 閱讀(565) 評論(0)  編輯 收藏 引用 所屬分類: ACM題目
            欧美va久久久噜噜噜久久| 国内精品久久久久久久久| 精品久久综合1区2区3区激情| 精品人妻伦九区久久AAA片69| 国产午夜精品久久久久九九| 久久午夜电影网| 久久久久一区二区三区| 99久久精品国产高清一区二区| 久久午夜伦鲁片免费无码| 久久成人国产精品| 国产亚洲精品美女久久久| 国产精品久久久天天影视| 久久99国产精品99久久 | 91久久九九无码成人网站| 国产精品久久久久久一区二区三区| 亚洲国产另类久久久精品小说| 亚洲精品午夜国产VA久久成人| 亚洲精品乱码久久久久66| 国产亚洲美女精品久久久2020| 18岁日韩内射颜射午夜久久成人| 精品久久人人爽天天玩人人妻| 无码人妻少妇久久中文字幕蜜桃| 久久综合香蕉国产蜜臀AV| A狠狠久久蜜臀婷色中文网| 久久这里只精品国产99热| 久久久精品国产亚洲成人满18免费网站 | 久久99热国产这有精品| 99久久精品免费看国产免费| 亚洲&#228;v永久无码精品天堂久久 | 热re99久久精品国99热| 99久久国产综合精品成人影院| 日日狠狠久久偷偷色综合0| 一本久久知道综合久久| 亚洲国产精久久久久久久| 亚洲欧美成人久久综合中文网| 伊人久久大香线蕉亚洲五月天| 色综合合久久天天综合绕视看 | 久久精品国产亚洲AV高清热 | 少妇人妻综合久久中文字幕| 久久美女网站免费| 久久久一本精品99久久精品88|