Intervals
Time Limit: 5000MS   Memory Limit: 65536K
Total Submissions: 7218   Accepted: 3011

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 ≤ KN ≤ 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
  
  这题就是求最大区间K覆盖,最大费用最大流走起~~~
 #include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
using namespace std;
const int INF=;
const int maxn=,maxm=;
int cnt,fir[maxn],nxt[maxm],to[maxm],cap[maxm],val[maxm],dis[maxn],path[maxn];
struct data{
int l,r,v;
bool operator <(const data A)const{
if(l!=A.l)
return l<A.l;
return r<A.r;
}
}ar[maxn]; struct data2{
int a,pos;
bool operator <(const data2 A)const{
if(a!=A.a)
return a<A.a;
return pos<A.pos;
}
}br[maxn]; void addedge(int a,int b,int c,int v)
{
nxt[++cnt]=fir[a];to[cnt]=b;cap[cnt]=c;val[cnt]=v;fir[a]=cnt;
}
int S,T;
int Spfa()
{
queue<int>q;
memset(dis,-,sizeof(dis));
q.push(S);dis[S]=;
while(!q.empty())
{
int node=q.front();q.pop();
for(int i=fir[node];i;i=nxt[i])
if(cap[i]&&dis[node]+val[i]>dis[to[i]]){
dis[to[i]]=val[i]+dis[node];
path[to[i]]=i;
q.push(to[i]);
}
}
return dis[T]==-?:dis[T];
} int Aug()
{
int p=T,f=INF;
while(p!=S)
{
f=min(f,cap[path[p]]);
p=to[path[p]^];
}
p=T;
while(p!=S)
{
cap[path[p]]-=f;
cap[path[p]^]+=f;
p=to[path[p]^];
}
return f;
} int MCMF()
{
int ret=,d;
while(d=Spfa())
ret+=Aug()*d;
return ret;
} int cont;
void Init()
{
cnt=;cont=;
memset(fir,,sizeof(fir));
} int main()
{
int Q,n,k;
scanf("%d",&Q);
while(Q--)
{
Init();
scanf("%d%d",&n,&k);
for(int i=;i<=n;i++)
scanf("%d%d%d",&ar[i].l,&ar[i].r,&ar[i].v);
sort(ar+,ar+n+);
for(int i=;i<=n;i++){
br[i*-].a=ar[i].l;br[i*].a=ar[i].r;
br[i*-].pos=br[i*].pos=i;
}
sort(br+,br+*n+);
for(int i=;i<=n;i++)
ar[i].l=ar[i].r=;
for(int i=;i<=*n;i++)
{
int p=br[i].pos;
if(!ar[p].l){
ar[p].l=++cont;
}
else{
ar[p].r=++cont;
}
} S=;T=cont+;
for(int i=;i<cont+;i++)
addedge(i,i+,k,),addedge(i+,i,,);
for(int i=;i<=n;i++)
addedge(ar[i].l,ar[i].r,,ar[i].v),addedge(ar[i].r,ar[i].l,,-ar[i].v);
printf("%d\n",MCMF());
} return ;
}

网络流(最大费用最大流) :POJ 3680 Intervals的更多相关文章

  1. poj 3680 Intervals(费用流)

    http://poj.org/problem?id=3680 巧妙的构图. 题目:给定N个区间(ai,bi)权值wi,求最大权和且每个点最多覆盖K次. 构图:将区间端点离散化,将第i个点连第i+1个点 ...

  2. POJ 3680: Intervals【最小费用最大流】

    题目大意:你有N个开区间,每个区间有个重量wi,你要选择一些区间,使得满足:每个点被不超过K个区间覆盖的前提下,重量最大 思路:感觉是很好想的费用流,把每个区间首尾相连,费用为该区间的重量的相反数(由 ...

  3. POJ 3680 Intervals 最小费用最大流(MCMF算法)

    题意:给出 n ,k 表示接下来给你 n 段开区间,每段区间都有它的权值,问选出一些区间,使它的权值最大,并且在实轴上的每个点,不得超过 k次被覆盖. 思路:首先要理解建图思路,首先有一个基图,相邻点 ...

  4. 网络流(最小费用最大流):POJ 2135 Farm Tour

    Farm Tour Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged on PKU. Original ID: ...

  5. poj 3680 Intervals

    给定N个带权的开区间,第i个区间覆盖区间(ai,bi),权值为wi.现在要求挑出一些区间使得总权值最大,并且满足实轴上任意一个点被覆盖不超过K次. 1<=K<=N<=200.1< ...

  6. HDU 6118 度度熊的交易计划(网络流-最小费用最大流)

    度度熊参与了喵哈哈村的商业大会,但是这次商业大会遇到了一个难题: 喵哈哈村以及周围的村庄可以看做是一共由n个片区,m条公路组成的地区. 由于生产能力的区别,第i个片区能够花费a[i]元生产1个商品,但 ...

  7. POJ 3680 Intervals(费用流)

    Intervals Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 5762   Accepted: 2288 Descrip ...

  8. POJ 3680 Intervals(费用流+负权优化)

    [题目链接] http://poj.org/problem?id=3680 [题目大意] 有N个带权重的区间,现在要从中选取一些区间, 要求任意点都不被超过K个区间所覆盖,请最大化总的区间权重. [题 ...

  9. Minimum Cost 【POJ - 2516】【网络流最小费用最大流】

    题目链接 题意: 有N个商家它们需要货物源,还有M个货物供应商,N个商家需要K种物品,每种物品都有对应的需求量,M个商家每种物品都是对应的存货,然后再是K个N*M的矩阵表示了K个物品从供货商运送到商家 ...

随机推荐

  1. poj 1849 Two

    /*poj 1849 two 思考一下会发现 就是求直径 直径上的中点就是两个人分开的地方(不再有交集)*/ #include<cstdio> #define maxn 100010 us ...

  2. Java集群之session共享解决方案

    随着互联网的日益壮大,网站的pv和uv成线性或者指数倍的增加.单服务器单数据库早已经不能满足实际需求.比如像盛大,淘宝这样的大型网络公司,更是如此.     集群,也就是让一组计算机服务器协同工作,达 ...

  3. HTML5表单提交和PHP环境搭建

    HTML5表单提交相关内容和PHP环境搭建需要的软件(只备注) (2)举例介绍 (3)PHP环境搭建

  4. js的MVC结构设计

    基于jquery的Deferred,设计出如下MVC架构. 模型model interface.js interface: function(userid){ var dtd = $.Deferred ...

  5. R文件丢失异常原因汇总

    引言: R文件丢失异常在java开发中是个比较常见的异常,造成这个异常的原因可能非常微小,但是给Android开发者们造成的麻烦可是巨大的,当程序员们费尽千辛万苦,找到自己错在哪里的时候,绝对会对自己 ...

  6. xctool工具

    xctool [1]xctool的特性: 原文:http://www.infoq.com/cn/news/2013/05/Facebook-buck-xctool-build xctool是Faceb ...

  7. 【转】 ios开发之倒计时实现的两种方法

    原文:http://blog.csdn.net/kylinbl/article/details/8972261 方法1:使用NSTimer来实现 主要使用的是NSTimer的scheduledTime ...

  8. 【转】无废话WCF系列教程

    转自:http://www.cnblogs.com/iamlilinfeng/category/415833.html     看后感:这系列的作者李林峰写得真的不错,通过它的例子,让我对WCF有了一 ...

  9. const详解

    详解C++中的const关键字

  10. Jquery 获取日期date()对象

    获取JavaScript 的时间使用内置的Date函数完成 var mydate = new Date(); mydate.getYear(); //获取当前年份(2位) mydate.getFull ...