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



            唐牛春季網(wǎng)絡(luò)流專場(chǎng)的一道題,今天做了一下。
            發(fā)現(xiàn)最小費(fèi)用流就能搞定,定義完數(shù)組發(fā)現(xiàn)如果以order為點(diǎn)肯定超時(shí)了,所以re看了一下題,發(fā)現(xiàn)t的范圍很小,都是整數(shù),所以果斷改圖,把每秒作為點(diǎn)就OK了。
            建圖方法:相鄰兩個(gè)點(diǎn)(t,t + 1)連線,流量是2,費(fèi)用是0,對(duì)于每一個(gè)order,s + 1和t + 2連線(t + 2多加1是因?yàn)榉乐褂衅鹗键c(diǎn)與它相同,出現(xiàn)流錯(cuò)誤)流量為1,費(fèi)用為-c,在這個(gè)圖上做一邊最小費(fèi)用流就行了。
            SPFA很犀利,不過(guò)極限數(shù)據(jù)還是跑不進(jìn)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 閱讀(86) 評(píng)論(0)  編輯 收藏 引用 所屬分類: 網(wǎng)絡(luò)流
            色综合久久久久综合体桃花网| 麻豆亚洲AV永久无码精品久久| 2021久久精品国产99国产精品 | 日本一区精品久久久久影院| 久久99国产精品一区二区| 久久www免费人成看国产片 | 久久亚洲AV成人出白浆无码国产| 欧美喷潮久久久XXXXx| 国产成人99久久亚洲综合精品| 7777精品伊人久久久大香线蕉| 久久狠狠高潮亚洲精品| 久久精品成人免费国产片小草| 97精品依人久久久大香线蕉97| 日韩欧美亚洲综合久久影院d3| 一本一道久久综合狠狠老| 久久精品人妻一区二区三区| 成人综合伊人五月婷久久| 中文精品久久久久人妻| 99久久国产免费福利| 欧美午夜精品久久久久免费视| 久久亚洲精品无码播放| 久久99国产精品一区二区| 久久精品卫校国产小美女| 久久影院午夜理论片无码| 热久久这里只有精品| jizzjizz国产精品久久| 综合久久国产九一剧情麻豆| 亚洲欧美一级久久精品| 久久黄色视频| 久久夜色精品国产亚洲av| 一本久久a久久精品综合夜夜| 97久久超碰国产精品2021| 久久精品人人槡人妻人人玩AV | 久久久久亚洲精品天堂久久久久久| 久久精品人人做人人爽97| 久久99热只有频精品8| 久久香蕉超碰97国产精品| 色欲久久久天天天综合网| 亚洲中文字幕久久精品无码喷水| 综合久久一区二区三区 | 久久精品一区二区|