POJ3680 Intervals
来源:互联网 发布:域名更新 编辑:程序博客网 时间:2024/06/06 02:23
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
43 11 2 22 3 43 4 83 11 3 22 3 43 4 83 11 100000 1000001 2 3100 200 3003 21 100000 1000001 150 301100 200 300
Sample Output
1412100000100301
Source
—————————————————————————————————
题目大意:给你n个区间(ai,bi),对应区间的权重为ci。现在让你挑选一些区间,使得任一点出现的次数不超过k,问你满足条件的方案的最大权重和为多少?
思路:最小费用最大流,先拿源点和每个左端点连边,流量为1.费用为0,汇点和右端点连边,流量为1,费用为0.区间左端点和右端点连边费用为-价值,流量为1,然后n2判区间是否重叠,不重叠就连一条费用0,流量无穷的边
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <cmath>#include <map>#include <set>#include <stack>#include <queue>#include <vector>#include <bitset>using namespace std;#define LL long longconst int INF = 0x3f3f3f3f;#define MAXN 100100#define MAXM 1000100int vis[MAXN],d[MAXN],pre[MAXN],aa[MAXN];struct Edge{ int u, v, c, cost, next;} edge[MAXM];int s[MAXN], cnt;void init(){ cnt = 0; memset(s, -1, sizeof(s));}void add(int u, int v, int c, int cost){ edge[cnt].u = u; edge[cnt].v = v; edge[cnt].cost = cost; edge[cnt].c = c; edge[cnt].next = s[u]; s[u] = cnt++; edge[cnt].u = v; edge[cnt].v = u; edge[cnt].cost = -cost; edge[cnt].c = 0; edge[cnt].next = s[v]; s[v] = cnt++;}bool spfa(int ss, int ee,int &flow,int &cost){ queue<int> q; memset(d, INF, sizeof d); memset(vis, 0, sizeof vis); d[ss] = 0, vis[ss] = 1, pre[ss] = 0, aa[ss] = INF; q.push(ss); while (!q.empty()) { int u = q.front(); q.pop(); vis[u] = 0; for (int i = s[u]; ~i; i = edge[i].next) { int v = edge[i].v; if (edge[i].c>0&& d[v]>d[u] + edge[i].cost) { d[v] = d[u] + edge[i].cost; pre[v] = i; aa[v] = min(aa[u], edge[i].c); if (!vis[v]) { vis[v] = 1; q.push(v); } } } } if (d[ee] == INF) return 0; flow += aa[ee]; cost += d[ee]*aa[ee]; int u = ee; while (u != ss) { edge[pre[u]].c -= aa[ee]; edge[pre[u] ^ 1].c += aa[ee]; u = edge[pre[u]].u; } return 1;}int MCMF(int ss, int ee){ int cost = 0, flow=0; while (spfa(ss, ee, flow, cost)); return cost;}int a[300],b[300];int main(){ int T,m,n,k,u,v,c; for(scanf("%d",&T);T--;) { init(); scanf("%d%d",&n,&k); add(100001,100002,k,0); add(100003,100004,k,0); for(int i=0;i<n;i++) { scanf("%d%d%d",&a[i],&b[i],&c); add(a[i],b[i],1,-c); add(100002,a[i],1,0); add(b[i],100003,1,0); } for(int i=0;i<n;i++) for(int j=0;j<n;j++) { if(b[i]<a[j]) add(b[i],a[j],1,0); } printf("%d\n",-MCMF(100001,100004)); } return 0;}
- poj3680 Intervals
- poj3680 Intervals
- poj3680 Intervals
- POJ3680 Intervals
- POJ3680-Intervals
- 费用流 poj3680 Intervals
- Intervals poj3680 费用流
- POJ3680: Intervals 题解
- 解题报告 之 POJ3680 Intervals
- POJ3680 Intervals(费用流)
- poj3680:Intervals(费用流)
- POJ3680——Intervals(费用流)
- POJ3680——Intervals(费用流)
- POJ3680 Intervals (区间K覆盖问题)
- POJ3680 Intervals 离散化+最小费用流
- 【POJ3680】Intervals 最小费用最大流
- poj3680 Intervals (费用流巧妙的建图)
- poj3680 Intervals 【最小费用最大流+离散化】
- 逻辑回归系数的意义
- OpenCV之putText()函数详解
- mybatis报错Result Maps collection already contains value for
- pbrt <1> 理解 为什么可以用 RGBSpectrum 来表示 Radiance
- [日常训练] 联络网
- POJ3680 Intervals
- iOS性能自动化之instruments
- POJ 3070 Fibonacci(矩阵快速幂)
- block,inline-block,inline之间的区别
- maven实战(四)聚合与继承
- 给java初学者的部分笔记3!
- toad edit界面 执行大量脚本(2w+)挂死解决办法
- 安装memcache
- python——asyncio模块实现协程、异步编程(三)