Intervals
Time Limit: 5000MS   Memory Limit: 65536K
Total Submissions: 8587   Accepted: 3662

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 题意:给你N个区间段的(a,b)和价值,让你在不相交的情况下求m次求得最大值。 题解:先将每个点都离散化,然后依次添加INF的边,然后输入m条边,用lower_bound找到x,y相应下标,然后加边权值为这个区间段的相反数,跑最小费用流就可以了 题解这里
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
const int N=;
const int M=1e4+;
const int INF=0x3f3f3f3f;
int head[N],tot,pre[N],C[N],F[N],V[N],n,m;
struct node{
int u,v,flow,cost,next;
}e[M];
void add(int u,int v,int flow,int cost){
e[tot].u=u;e[tot].v=v;e[tot].flow=flow;e[tot].cost=cost;e[tot].next=head[u];head[u]=tot++;
e[tot].u=v;e[tot].v=u;e[tot].flow=;e[tot].cost=-cost;e[tot].next=head[v];head[v]=tot++;
}
int SPFA(int s,int t){
memset(pre,-,sizeof(pre));
for(int i=;i<=t+;++i) F[i]=,C[i]=INF,V[i]=;
queue<int>Q;
Q.push(s);
C[]=,F[]=INF,V[]=;
while(!Q.empty()){
int u=Q.front();
Q.pop();
V[u]=;
for(int i=head[u];~i;i=e[i].next){
int v=e[i].v,f=e[i].flow,c=e[i].cost;
if(f>&&C[v]>C[u]+c) {
C[v]=C[u]+c;
pre[v]=i;
F[v]=min(f,F[u]);
if(!V[v]) V[v]=,Q.push(v);
}
}
}
return F[t]&&C[t]!=;
}
int MCMF(int s,int t){
int ans=,temp;
while(temp=SPFA(s,t)){
for(int i=pre[t];~i;i=pre[e[i].u]) {
ans+=temp*e[i].cost;
e[i].flow-=temp;
e[i^].flow+=temp;
}
}
return ans;
}
struct point{
int x,y,val;
}Po[N];
int ar[N];
int main(){
int T;
for(scanf("%d",&T);T--;){
scanf("%d%d",&n,&m);
tot=;
memset(head,-,sizeof(head));
int ct=;
for(int i=;i<=n;++i) {scanf("%d%d%d",&Po[i].x,&Po[i].y,&Po[i].val);
ar[++ct]=Po[i].x,ar[++ct]=Po[i].y;
}
sort(ar+,ar+ct+);
int num=;
for(int i=;i<=ct;++i) {
while(ar[i]==ar[num-]&&i<ct) ++i;
if(i<=ct) ar[num++]=ar[i];
}
for(int i=;i<=num;++i) add(i-,i,INF,);
add(,,m,);
add(num,num+,m,);
for(int i=;i<=n;++i) {
int l=lower_bound(ar+,ar+num+,Po[i].x)-ar;
int r=lower_bound(ar+,ar+num+,Po[i].y)-ar;
add(l,r,,-Po[i].val);
}
printf("%d\n",-MCMF(,num+));
}
}

poj3680 最大权不相交路径的更多相关文章

  1. POJ Air Raid 【DAG的最小不相交路径覆盖】

    传送门:http://poj.org/problem?id=1422 Air Raid Time Limit: 1000MS   Memory Limit: 10000K Total Submissi ...

  2. [luoguP2765] 魔术球问题(最大流—最小不相交路径覆盖)

    传送门 枚举球的个数 num 如果 i < j && (i + j) 是完全平方数,那么 i -> j' 连一条边 再加一个超级源点 s,s -> i 再加一个超级汇 ...

  3. 不相交路径[BZOJ1471] 容斥原理 拓扑排序

    最近学容斥的时候又碰到一道类似的题目,所以想分享一个套路,拿这题来举例 [题目描述] 给出一个\(N(N\leq 150)\)个结点的有向无环简单图.给出4个不同的点\(a,b,c,d\),定义不相交 ...

  4. [bzoj 1471] 不相交路径 (容斥原理)

    题目描述 给出一个N(n<=150)N(n<=150)N(n<=150)个结点的有向无环简单图.给出444个不同的点aaa,bbb,ccc,ddd,定义不相交路径为两条路径,两条路径 ...

  5. Air Raid POJ - 1422 【有向无环图(DAG)的最小路径覆盖【最小不相交路径覆盖】 模板题】

    Consider a town where all the streets are one-way and each street leads from one intersection to ano ...

  6. P2172 [国家集训队]部落战争 二分图最小不相交路径覆盖

    二分图最小不相交路径覆盖 #include<bits/stdc++.h> using namespace std; ; ; ; ], nxt[MAXM << ], f[MAXM ...

  7. HDU 5852 Intersection is not allowed! ( 2016多校9、不相交路径的方案、LGV定理、行列式计算 )

    题目链接 题意 : 给定方格中第一行的各个起点.再给定最后一行与起点相对应的终点.问你从这些起点出发到各自的终点.不相交的路径有多少条.移动方向只能向下或向右 分析 : 首先对于多起点和多终点的不相交 ...

  8. LGV - 求多条不相交路径的方案数

    推荐博客 :https://blog.csdn.net/qq_25576697/article/details/81138213 链接:https://www.nowcoder.com/acm/con ...

  9. LGV 引理——二维DAG上 n 点对不相交路径方案数

    文章目录 引入 简介 定义 引理 证明 例题 释疑 扩展 引入 有这样一个问题: 甲和乙在一张网格图上,初始位置 ( x 1 , y 1 ) , ( x 2 , y 2 ) (x_1,y_1),(x_ ...

随机推荐

  1. 美版健康码要来了!苹果Google被网友质疑:这是变相的监视系统吗?

    4 月 30 日消息,据外媒报道,由苹果和谷歌合作开发一个冠状病毒追踪系统将在 5 月 1 日正式上架,今天已经进入测试阶段. 图自:techcrunch 这款应用可以让 iOS 和 Android ...

  2. 负载均衡服务之HAProxy访问控制ACL

    前文我们聊到了haproxy的错误页的配置,自定义日志的配置,回顾请参考https://www.cnblogs.com/qiuhom-1874/p/12797913.html:今天我们主要来看看hap ...

  3. 源码学习VUE之Observe

    在文章 源码学习VUE之响应式原理我们大概描述了响应式的实现流程,主要写了observe,dep和wather的简易实现,以及推导思路.但相应代码逻辑并不完善,今天我们再来填之前的一些坑. Obser ...

  4. 全面解析Java语言 Java技能优化集锦

    通用篇 "通用篇"讨论的问题适合于大多数Java应用. 不用new关键词创建类的实例 用new关键词创建类的实例时,构造函数链中的所有构造函数都会被自动调用.但如果一个对象实现了C ...

  5. ACM--[kuangbin带你飞]--专题1-23

    专题一 简单搜索 POJ 1321 棋盘问题POJ 2251 Dungeon MasterPOJ 3278 Catch That CowPOJ 3279 FliptilePOJ 1426 Find T ...

  6. POJ 2188 Cow Laundry

    Cow Laundry Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1376 Accepted: 886 Descriptio ...

  7. P2480 [SDOI2010]古代猪文

    P2480 [SDOI2010]古代猪文 比较综合的一题 前置:Lucas 定理,crt 求的是: \[g^x\bmod 999911659,\text{其中}x=\sum_{d\mid n}\tbi ...

  8. .net core 基于Dapper 的分库分表开源框架(core-data)

    一.前言 感觉很久没写文章了,最近也比较忙,写的相对比较少,抽空分享基于Dapper 的分库分表开源框架core-data的强大功能,更好的提高开发过程中的效率: 在数据库的数据日积月累的积累下,业务 ...

  9. 【MIT6.828】centos7下使用Qemu搭建xv6运行环境

    title:[MIT6.828]centos7下使用Qemu搭建xv6运行环境 date: "2020-05-05" [MIT6.828]centos7下搭建xv6运行环境 1. ...

  10. Oracle的三种循环

    一.loop循环 语法:声明循环变量loop判断循环条件 ,如果循环条件不成立,跳出循环if 条件表达式 thenexit;end if;语句块;改变循环变量的值end loop; 举例:输出1到10 ...