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. Linux 关闭及重启方式

    一.shutdown 命令 作用:关闭或重启系统 使用权限:超级管理员使用 常用选项 1. -r 关机后立即重启 2. -h关机后不重启 3. -f快速关机,重启时跳过fsck(file system ...

  2. atoi、stoi、strtoi区别

    首先atoi和strtol都是c里面的函数,他们都可以将字符串转为int,它们的参数都是const char*,因此在用string时,必须调c_str()方法将其转为char*的字符串.或者atof ...

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

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

  4. Axiom3D学习日记 0.Axiom基础知识

    Axiom 3D Engine An open-source, cross-platform, managed 3D rendering engine for DirectX, XNA and Ope ...

  5. TreeView checkbox

    C# TreeView checkbox 联动打勾 #region 将树的checkbox选中 private void setNodeTrue(Node selNode) { Node node = ...

  6. 佳博GprinterApp编辑软件使用说明

    佳博打印机代理商淘宝店https://shop107172033.taobao.com/index.htm?spm=2013.1.w5002-9520741823.2.Sqz8Pf 在此店购买的打印机 ...

  7. Bootstrap_表单_表单样式

    一.基础表单 <form > <div class="form-group"> <label>邮箱:</label> <inp ...

  8. js获取当前时间戳与日期比较

    如何用javascript获取当前时间戳: 复制代码 代码示例: 方法1: var timestamp = date.parse(new date()); 结果:1280977330000 方法2: ...

  9. php 文件上传后缀名与文件类型对照表(几乎涵盖所有文件)

    网上有很多php文件上传的类,文件上传处理是php的一个特色(至少手册上是将此作为php特点来展示的,个人认为php在数组方面的优异功能更有特 色),学php的人都知道文件上传怎么做,但很多人在编程中 ...

  10. TatukGIS-TGIS_ShapeArc.GetPointOnLine

    function GetPointOnLine(const _distance: Double; const _offset: Double; const _part: Integer): TGIS_ ...