poj3680 最大权不相交路径
| 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 ≤ K ≤ N ≤ 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 最大权不相交路径的更多相关文章
- POJ Air Raid 【DAG的最小不相交路径覆盖】
传送门:http://poj.org/problem?id=1422 Air Raid Time Limit: 1000MS Memory Limit: 10000K Total Submissi ...
- [luoguP2765] 魔术球问题(最大流—最小不相交路径覆盖)
传送门 枚举球的个数 num 如果 i < j && (i + j) 是完全平方数,那么 i -> j' 连一条边 再加一个超级源点 s,s -> i 再加一个超级汇 ...
- 不相交路径[BZOJ1471] 容斥原理 拓扑排序
最近学容斥的时候又碰到一道类似的题目,所以想分享一个套路,拿这题来举例 [题目描述] 给出一个\(N(N\leq 150)\)个结点的有向无环简单图.给出4个不同的点\(a,b,c,d\),定义不相交 ...
- [bzoj 1471] 不相交路径 (容斥原理)
题目描述 给出一个N(n<=150)N(n<=150)N(n<=150)个结点的有向无环简单图.给出444个不同的点aaa,bbb,ccc,ddd,定义不相交路径为两条路径,两条路径 ...
- Air Raid POJ - 1422 【有向无环图(DAG)的最小路径覆盖【最小不相交路径覆盖】 模板题】
Consider a town where all the streets are one-way and each street leads from one intersection to ano ...
- P2172 [国家集训队]部落战争 二分图最小不相交路径覆盖
二分图最小不相交路径覆盖 #include<bits/stdc++.h> using namespace std; ; ; ; ], nxt[MAXM << ], f[MAXM ...
- HDU 5852 Intersection is not allowed! ( 2016多校9、不相交路径的方案、LGV定理、行列式计算 )
题目链接 题意 : 给定方格中第一行的各个起点.再给定最后一行与起点相对应的终点.问你从这些起点出发到各自的终点.不相交的路径有多少条.移动方向只能向下或向右 分析 : 首先对于多起点和多终点的不相交 ...
- LGV - 求多条不相交路径的方案数
推荐博客 :https://blog.csdn.net/qq_25576697/article/details/81138213 链接:https://www.nowcoder.com/acm/con ...
- LGV 引理——二维DAG上 n 点对不相交路径方案数
文章目录 引入 简介 定义 引理 证明 例题 释疑 扩展 引入 有这样一个问题: 甲和乙在一张网格图上,初始位置 ( x 1 , y 1 ) , ( x 2 , y 2 ) (x_1,y_1),(x_ ...
随机推荐
- 鸟哥Linux私房菜(基础篇)——第五章:首次登入与在线求助 man page笔记
1.X Winsows与文本模式的切换 ●[Ctrl] + [Alt] + [F1] ~ [F6] :文字接口登入 tty1 ~ tty6 终端机. ●[Ctrl] + [Alt] + ...
- 基于docker-compose部署LNMP
一.配置环境 [root@docker ~]# systemctl stop firewalld[root@docker ~]# iptables -F[root@docker ~]# setenfo ...
- Linux系统管理第二次作业 目录和文件管理 rpm安装 创建yum仓库
chapter02 - 03 作业 1.分别用cat \tac\nl三个命令查看文件/etc/ssh/sshd_config文件中的内容,并用自己的话总计出这三个文档操作命令的不同之处? [ ...
- java 之 jsp tomcat启动失败问题
问题描述: 创建了一个helloServlet 代码如下 package Test; import java.io.IOException; import javax.servlet.ServletE ...
- SpringCloud系列之集成Dubbo应用篇
目录 前言 项目版本 项目说明 集成Dubbo 2.6.x 新项目模块 老项目模块 集成Dubbo 2.7.x 新项目模块 老项目模块 参考资料 系列文章 前言 SpringCloud系列开篇文章就说 ...
- 集合框架-day10
day10-集合框架-对象数组的概述与引用 1 集合框架的简单介绍: A:集合的由来 数组长度是固定,当添加的元素超过了数组的长度时需要对数组重新定义,太麻烦,java内部给我们提供了集合类,能存储任 ...
- JS省城级联
2019独角兽企业重金招聘Python工程师标准>>> 这里是HTML内容 <label class="control-label col-md-2 col-sm-3 ...
- 最大公约数gcd、最小公倍数lcm
最大公约数(辗转相除法) 循环: int gcd(int a,int b) { int r; ) { r=b%a; b=a; a=r; } return b; } 递归: int gcd(int a, ...
- 12c DG broker DMON自动重启过程分析
一.知识点 1.强烈建议大家管理dataguard使用broker. 2.broker的日志要知道在哪里,会看日志是学习的第一步. 3.体系结构需要看官方文档. 二.测试过程 1.查看DMON进程 & ...
- 百度Openrasp开源的应用运行时自我保护产品,安装教程。
第一步: 下载最新版本的安装包 https://packages.baidu.com/app/openrasp/release/latest/rasp-php-linux.tar.bz2 解压到目录: ...