poj3680 Intervals
Intervals
Time Limit: 5000MS
Memory Limit: 65536K
Total Submissions: 7161
Accepted: 2982
Description
You are given N weighted open intervals. The ith interval covers (ai, bi) and weighs wi. Your task is to pick some of the intervals to maximize the total weights under the limit that no point in the real axis is covered more than k times.
Input
The first line of input is the number of test case.
The first line of each test case contains two integers, N and K (1 ≤ K ≤ N ≤ 200).
The next N line each contain three integers ai, bi, wi(1 ≤ ai < bi ≤ 100,000, 1 ≤ wi ≤ 100,000) describing the intervals.
There is a blank line before each test case.
Output
For each test case output the maximum total weights in a separate line.
Sample Input
4
3 1
1 2 2
2 3 4
3 4 8
3 1
1 3 2
2 3 4
3 4 8
3 1
1 100000 100000
1 2 3
100 200 300
3 2
1 100000 100000
1 150 301
100 200 300
Sample Output
14
12
100000
100301
Source
POJ Founder Monthly Contest – 2008.07.27, windy7926778
費用流,構圖方法很巧妙。
我一開始的想法是區間放左邊,點放右邊,跑費用流。後來發現顯然是錯的,因為在最大流時源點流入區間的邊不一定滿流,也就是一個區間內的點沒有全部覆蓋,這顯然是錯誤的。
下面是正確地做法:要保證每個點最多覆蓋k次,可以把所有點串聯起來,每個點向後一個點連一條容量k、費用0的邊。(是不是很機智啊!!)然後對於區間[a,b],從a到b連一條容量1、費用w的邊就可以了。最後從源點到1點、從n點到匯點,分別連一條容量k、費用0的點。
至於這個方法的正確性如何證明呢??我可以說只可意會不可言傳嗎=_=……大家自己腦補吧……額
如此看來,構圖真是一種藝術啊!
#include
#include
#include
#include
#include
#include
#include
#include