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. LVS+Keepalived 实现高可用负载均衡集群

    LVS+Keepalived  实现高可用负载均衡集群     随着网站业务量的增长,网站的服务器压力越来越大?需要负载均衡方案!商业的硬件如 F5 ,Array又太贵,你们又是创业型互联公司如何有效 ...

  2. Linux中的常用符号

    >, 1>     输出重定向符stdout,代码为1,重定向内容到文件,清除已有的内容,然后加入新内容,如果文件不存在还会创建文件 >>, 1>>   追加输出重 ...

  3. mysql查询语句中like 的用法

    1.常见用法: (1)搭配%使用 %代表一个或多个字符的通配符,譬如查询字段name中以大开头的数据: (2)搭配_使用 _代表仅仅一个字符的通配符,把上面那条查询语句中的%改为_,会发现只能查询出一 ...

  4. 一只简单的网络爬虫(基于linux C/C++)————读取命令行参数及日志宏设计

    linux上面的程序刚开始启动的时候一般会从命令行获取某些参数,比如以守护进程运行啊什么的,典型的例子就是linux下的man,如下图所示 实现该功能可以使用getopt函数实现,该函数在头文件uni ...

  5. IP 基础知识全家桶,45 张图一套带走

    前言 前段时间,有读者希望我写一篇关于 IP 分类地址.子网划分等的文章,他反馈常常混淆,摸不着头脑. 那么,说来就来!而且要盘就盘全一点,顺便挑战下小林的图解功力,所以就来个 IP 基础知识全家桶. ...

  6. Programming Languages_04 Deferred Substitution

    Deferred Substitution 在执行出现with时,利用"substitution",每次with的出现,它都绕着整个body置换.这一方式是由F1WAE到env再到 ...

  7. P2765 魔术球问题 网络流二十四题重温

    P2765 魔术球问题 知识点::最小点覆盖 这个题目要拆点,这个不是因为每一个球只能用一次,而是因为我们要求最小点覆盖,所以要拆点来写. 思路: 首先拆点,然后就是开始建边,因为建边的条件是要求他们 ...

  8. springboot设置过滤器、监听器、拦截器

    其实这篇文章算不上是springboot的东西,我们在spring普通项目中也是可以直接使用的 设置过滤器: 以前在普通项目中我们要在web.xml中进行filter的配置,但是只从servlet 3 ...

  9. SpringBoot:Demo

    目录 Demo 准备工作 登录+拦截器 Restful CRUD Restful架构 查询所有员工 添加员工 员工修改功能 HiddenHttpMethodFilter 删除员工 定制错误页面 注销功 ...

  10. LTE网络概述

    LTE主要由两部分组成:无线接入技术演进(E-UTRAN)+系统架构演进(SAE):其中,SAE主要含有的是演进型分组交换核心网(EPC),其控制处理部分为移动性管理实体(MME),数据承载部分称为业 ...