POJ 3680 Intervals 费用流+离散化

本文探讨了在给定的区间集合中,如何选择部分区间以最大化总权重,同时确保任意点的覆盖次数不超过给定阈值的问题。通过构建特定类型的图并应用增广路径算法,实现了解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Intervals
Time Limit: 5000MS Memory Limit: 65536K
Total Submissions: 6930 Accepted: 2884

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

Source

POJ Founder Monthly Contest – 2008.07.27, windy7926778


引用一个题解

有N个整数区间,每个区间有一个权值,从中取一些区间,使得任意整数点的重叠数不大于K,并且这些区间的总权值最大。

http://blog.youkuaiyun.com/waitfor_/article/details/7380406 引用这个题解

建图从0->1,1->2,~~~~~n->n+1每条边容量为k,费用为0,

对于每条线段,他的两个端点连边容量为1,费用-w

算法正确性证明:

如果两个区间没有交集,那么代表它们的边可以出现在同一增广路上,这一点显然。否则,它们就在不同的增广路上。每一个区间对应的边的容量都是1,这样,最后的流量就是被选出的两两有交集的区间的数量。受到(0,1,k,0)这条边的容量限制,这个值刚好不大于k.区间的权都是正的,因此选取的区间多多益善,所以流量必然最大。

 (对于每次选取的增广路中总存在一个区间,在每次增广所得区间都与这个区间有交集)



#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <stack>
#define ALL(v) (v).begin(),(v).end()
#define foreach(i,v) for (__typeof((v).begin())i=(v).begin();i!=(v).end();i++)
#define SIZE(v) ((int)(v).size())
#define mem(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define lp(k,a) for(int k=1;k<=a;k++)
#define lp0(k,a) for(int k=0;k<a;k++)
#define lpn(k,n,a) for(int k=n;k<=a;k++)
#define lpd(k,n,a) for(int k=n;k>=a;k--)
#define sc(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d %d",&a,&b)
#define lowbit(x) (x&(-x))
#define ll int
#define pi pair<int,int>
#define vi vector<int>
#define PI acos(-1.0)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define TT cout<<"*****"<<endl;
#define TTT cout<<"********"<<endl;

using namespace std;
#define inf 0x3f3f3f3f
#define Inf 0x3FFFFFFFFFFFFFFFLL
#define N 5000
#define M 5000

struct Edge
{
    ll to,cap,cost,nex;
    Edge() {}
    Edge(ll to,ll cap,ll cost,ll next):to(to),cap(cap),cost(cost),nex(next) {}
} edge[M];

struct{
    int a,b,w;
}line[210];

ll head[N],top;
ll D[N],A[N],P[N],li[N];
bool inq[N];

void add(ll from,ll to,ll cap,ll cost)
{
    edge[top]=Edge(to,cap,cost,head[from]);
    head[from]=top++;
    edge[top]=Edge(from,0,-cost,head[to]);
    head[to]=top++;
}

bool spfa(ll s,ll t,ll &flow,ll &cost)
{
    for(ll i=0;i<=t;i++) D[i]=inf;
    mem(inq);
    queue<ll>q;
    q.push(s);
    D[s]=0;
    A[s]=inf;
    while(!q.empty())
    {
        ll u=q.front();
        q.pop();
        inq[u]=0;
        for(ll i=head[u];~i;i=edge[i].nex)
        {
            Edge &e=edge[i];
            if(e.cap && D[e.to]>D[u]+e.cost)
            {
                D[e.to]=D[u]+e.cost;
                P[e.to]=i;
                A[e.to]=min(A[u],e.cap);
                if(!inq[e.to])
                {
                    inq[e.to]=1;
                    q.push(e.to);
                }
            }
        }
    }
    if(D[t]==inf) return false;
    cost+=D[t]*A[t];
    flow+=A[t];
    ll u=t;
    while(u!=s)
    {
        edge[P[u]].cap-=A[t];
        edge[P[u]^1].cap+=A[t];
        u=edge[P[u]^1].to;
    }
    return true;
}

ll mcmf(ll s,ll t)
{
    ll flow=0, cost=0;
    while(spfa(s,t,flow,cost));
    return cost;
}


int a[N],S,T,n,m,k,u,v,w,cnt;
void init()
{
    mem1(head);
    cnt=0;
    top=0;
    lp(i,m)
    {
        sc2(u,v); sc(w);
        li[cnt++]=u;
        li[cnt++]=v;
        line[i].a=u;
        line[i].b=v;
        line[i].w=w;
    }

    sort(li,li+cnt);
    n=unique(li,li+cnt)-li;
    S=0;
    T=n+1;
    lp(i,n+1)
        add(i-1,i,k,0);

    lp(i,m)
    {
        int x=lower_bound(li,li+n,line[i].a)-li+1;
        int y=lower_bound(li,li+n,line[i].b)-li+1;
        add(x,y,1,-line[i].w);
    }
}

int main()
{
    //freopen("in.txt","r",stdin);
    int t;
    sc(t);
    while(t--)
    {
        scanf("%d%d",&m,&k);
        init();
        int cost=mcmf(S,T);
        printf("%d\n",-cost);
    }
    return 0;
}




内容概要:本文档详细介绍了一个基于MATLAB实现的电力负荷预测项目,该项目运用遗传算法(GA)优化支持向量回归(SVR)和支持向量机(SVM)模型的超参数及特征选择。项目旨在解决电力系统调度、发电计划、需求侧响应等多个应用场景中的关键问题,特别是在应对高比例可再生能源接入带来的非线性、非平稳负荷预测挑战。文中涵盖了从数据接入、特征工程、模型训练到部署上线的全程,包括详细的代码示例和GUI设计,确保方案的可复现性和实用性。 适用人群:具备一定编程基础,尤其是熟悉MATLAB语言和机器学习算法的研发人员;从事电力系统调度、电力市场交易、新能源消纳等相关领域的工程师和技术专家。 使用场景及目标:①通过构建面向小时级别的滚动预测,输出高分辨率负荷轨迹,为日内与日前滚动调度提供边际成本最小化的依据;②在负荷高峰和供给紧张时,通过价格信号或直接负荷控制实施需求侧响应,提升削峰效率并抑制反弹;③为灵活性资源(调峰机组、储能、可中断负荷)提供更清晰的出清路径,降低弃风弃光率,提升系统整体清洁度;④帮助市场主体更准确地评估边际出清价格变化,提高报价成功率与收益稳定性,同时降低由预测偏差带来的风险敞口;⑤在运维与审计场景中,对预测产生的原因进行说明,保障业务侧与监管侧的可追溯性。 阅读建议:此资源不仅提供了完整的代码实现和GUI设计,更注重于理解GA优化过程中涉及到的数据处理、特征构造、模型选择及评估等核心步骤。因此,在学习过程中,建议结合实际案例进行实践,并深入研究每个阶段的具体实现细节,特别是适应度函数的设计、超参数空间的定义以及多样性维护机制的应用。此外,关注项目中关于数据对齐、缺失值处理、特征标准化等方面的最佳实践,有助于提高模型的鲁棒性和泛化能力。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值