• <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>
            posts - 7,comments - 3,trackbacks - 0
            2726 Plan
            FJ has two same house for rant. Now he has n (1 ≤ n ≤ 1000) piece of order, the orders are 
            given in the form: 
            s t v
            means that someone want to rant a house from the day s to t paying v yuan totally (including 
            the day s and t, 0 ≤ s ≤ t ≤ 400, 0 ≤ v ≤ 100,0000). 
            A hours can be only rant to one person, and FJ should either accept an order totally or reject it. 
            Input
            The first line of input file is a single integer T - The number of test cases. For each test case, 
            the first line is a single integer n then there n lines, each line gives an order
            Output
            For each data set, print a single line containing an integer, the maximum total income for the 
            data set
            Sample Input
            3
            4
            1 2 10
            2 3 10
            3 3 10
            1 3 10
            6
            1 20 1000
            3 25 10000
            5 15 5000
            22 300 5500
            10 295 9000
            7 7 6000
            8
            32 251 2261
            123 281 1339
            211 235 5641
            162 217 72736
            22 139 7851
            194 198 9190
            119 274 878
            122 173 8640
            Sample Output
            30
            25500
            38595



            唐牛春季網絡流專場的一道題,今天做了一下。
            發現最小費用流就能搞定,定義完數組發現如果以order為點肯定超時了,所以re看了一下題,發現t的范圍很小,都是整數,所以果斷改圖,把每秒作為點就OK了。
            建圖方法:相鄰兩個點(t,t + 1)連線,流量是2,費用是0,對于每一個order,s + 1和t + 2連線(t + 2多加1是因為防止有起始點與它相同,出現流錯誤)流量為1,費用為-c,在這個圖上做一邊最小費用流就行了。
            SPFA很犀利,不過極限數據還是跑不進0.00s.....
            代碼:
            #include <cstdio>
            #include 
            <cstring>
            #define min(a, b) (a > b ? b : a)
            using namespace std;

            const int maxn = 405;
            const int maxm = 3300;
            const int inf = 1 << 30;
            int n;

            struct Edge
            {
                
            int v, next, c, w;
            } edge[maxm];

            int head[maxn], cnt;

            void add_edge(int u, int v, int w, int c)
            {
                edge[cnt].v 
            = v;
                edge[cnt].w 
            = w;
                edge[cnt].c 
            = c;
                edge[cnt].next 
            = head[u];
                head[u] 
            = cnt++;

                edge[cnt].v 
            = u;
                edge[cnt].w 
            = 0;
                edge[cnt].c 
            = -c;
                edge[cnt].next 
            = head[v];
                head[v] 
            = cnt++;
            }

            int dis[maxn], pre[maxn];
            int alpha[maxn];
            int que[maxn], qhead, qrear;

            int spfa(int s, int e)
            {
                
            for (int i = 0; i < maxn; ++i)
                    dis[i] 
            = inf;
                memset(alpha, 
            0sizeof(alpha));
                dis[s] 
            = 0;
                que[qhead 
            = 0= s;
                qrear 
            = 1;
                alpha[s] 
            = 1;
                
            while (qhead != qrear)
                {
                    
            int k = que[qhead++];
                    qhead 
            %= maxn;
                    alpha[k] 
            = 0;
                    
            for (int q = head[k]; ~q; q = edge[q].next)
                        
            if (edge[q].w)
                            
            if (dis[k] + edge[q].c < dis[edge[q].v])
                            {
                                dis[edge[q].v] 
            = dis[k] + edge[q].c;
                                pre[edge[q].v] 
            = q;
                                
            if (!alpha[edge[q].v])
                                {
                                    alpha[edge[q].v] 
            = true;
                                    
            if (edge[q].c < 0)
                                    {
                                        qhead 
            = (qhead - 1 + maxn) % maxn;
                                        que[qhead] 
            = edge[q].v;
                                    }
                                    
            else
                                    {
                                        que[qrear
            ++= edge[q].v;
                                        qrear 
            %= maxn;
                                    }
                                }
                            }
                }
                
            if (dis[e] == inf) return -1;
                
            int k = inf;
                
            for (int i = e; i != s; i = edge[pre[i] ^ 1].v)
                   k 
            = min(k, edge[pre[i]].w);
                
            return k;
            }

            int mcmf(int s, int t)
            {
                
            int ans = 0, k;
                
            while (~(k = spfa(s, t)))
                {
                    
            for (int i = t; i != s; i = edge[pre[i] ^ 1].v)
                    {
                        edge[pre[i]].w 
            -= k;
                        edge[pre[i] 
            ^ 1].w += k;
                    }
                    ans 
            += dis[t] * k;
                }
                
            return ans;
            }

            void init()
            {
                cnt 
            = 0;
                memset(head, 
            -1sizeof(head));
            }

            int main()
            {
                
            int T;
                scanf(
            "%d"&T);
                
            while (T--)
                {
                    init();
                    scanf(
            "%d"&n);
                    
            for (int i = 0; i < n; ++i)
                    {
                        
            int a, b, c;
                        scanf(
            "%d%d%d"&a, &b, &c);
                        add_edge(a 
            + 1, b + 21-c);
                    }
                    
            for (int i = 0; i <= 401++i)
                        add_edge(i, i 
            + 120);
                    
            int ans = mcmf(0402);
                    printf(
            "%d\n"-ans);
                }
            }
            posted on 2011-10-15 22:20 LLawliet 閱讀(91) 評論(0)  編輯 收藏 引用 所屬分類: 網絡流
            蜜桃麻豆www久久| 久久成人永久免费播放| 久久亚洲AV成人出白浆无码国产| 色播久久人人爽人人爽人人片AV| 久久棈精品久久久久久噜噜| 国产精品无码久久四虎| 中文字幕精品久久久久人妻| 久久精品人人做人人爽电影蜜月| 国内精品久久久久久久久电影网| 99久久国产亚洲综合精品| 久久久久久综合一区中文字幕 | 久久精品一本到99热免费| 久久九九精品99国产精品| 久久精品国产色蜜蜜麻豆| 国产成人精品白浆久久69| 欧美久久久久久午夜精品| 99久久久国产精品免费无卡顿| 亚洲国产精品嫩草影院久久| 日韩精品久久久久久| 无码AV波多野结衣久久| 亚洲精品午夜国产va久久| 国产精品久久久久一区二区三区| 伊人久久精品无码二区麻豆| 欧美大战日韩91综合一区婷婷久久青草 | 久久久久久久尹人综合网亚洲| 久久伊人五月丁香狠狠色| 精品久久人人爽天天玩人人妻| 国产成人久久AV免费| 久久婷婷五月综合色高清| 伊人久久大香线焦AV综合影院 | 久久综合视频网站| 国产一区二区三精品久久久无广告 | 精品多毛少妇人妻AV免费久久| 久久精品www人人爽人人| 无码精品久久久天天影视| 伊人久久大香线蕉综合Av| 日韩精品久久久久久久电影蜜臀 | 久久亚洲日韩精品一区二区三区| 国产成人久久精品一区二区三区| 久久精品国产99国产精品导航| 久久久久久久97|