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. JDK14的新特性

    文章目录 虽然JDK13在今年的9月17号才发布,但是丝毫不会影响到下一个版本JDK14的开发工作.听说官方定的新功能马上就要官宣了,我们这里不妨来提前推断一下. 在9月17号的发布中,Oracle提 ...

  2. 【BUG之group_concat默认长度限制】

    2019独角兽企业重金招聘Python工程师标准>>> 问题:mysql数据库使用group_concat将多个id组成字符串数组,一共200个,到160个被截断: 原因:mysql ...

  3. CloudCC CRM探讨:精细流程管理与员工悟性培养

    很多企业主招聘时更喜欢专业的销售,来给他们创造价值.老板不愿意花时间在"磨刀上",而喜欢员工一来就"砍柴".即使是建立培训机制,仍然很大程度依赖于员工自己的悟性 ...

  4. muduo网络库源码学习————线程类

    muduo库里面的线程类是使用基于对象的编程思想,源码目录为muduo/base,如下所示: 线程类头文件: // Use of this source code is governed by a B ...

  5. 应用开发实践之关系型数据库(以MySql为例)小结

    本文主要是对目前工作中使用到的DB相关知识点的总结,应用开发了解到以下深度基本足以应对日常需求,再深入下去更偏向于DB本身的理论.调优和运维实践. 不在本文重点关注讨论的内容(可能会提到一些): 具体 ...

  6. MySQL 入门(2):索引

    摘要 在这篇文章中,我会先介绍一下什么是索引,索引有什么作用. 之后会介绍一下索引的数据结构是什么样的,有什么优点,又会带来什么样的问题. 在分析完数据结构后,我们可以根据这个数据结构,研究索引的用法 ...

  7. Python第三方库之Numpy库

    概述 Numpy  最基本的库,是用于处理含有同种元素的多维数组运算的第三方库 —科学计算包,python数据分析及科学计算的基础库,几乎支撑所有其他库 —支持N维数组运算.处理大型矩阵.成熟的广播函 ...

  8. Java——Lambda表达式

    一.Lambda表达式入门 我们先来看一段代码:匿名内部类的方式实现参数的传递 interface Command{ public abstract void test(); } public cla ...

  9. 基于OpenCV的KNN算法实现手写数字识别

    基于OpenCV的KNN算法实现手写数字识别 一.数据预处理 # 导入所需模块 import cv2 import numpy as np import matplotlib.pyplot as pl ...

  10. shell命令之巧用cut

    需求:取出日志中ip字段,并进行统计排序 .一般用用awk命令 假如ip地址为第一个字段 那么 awk ‘{print $1}’ 文件名 |sort |uniq -c|sort-nr 那如果不是第一个 ...