P1251 餐巾计划问题

传送门

想象一下餐巾的转移,从前一天到后一天,从外面买来,送到其他地方去洗然后过几天回来

发现很像一个流

所以考虑构建网络流模型

建立一个源点 $S$ ,和汇点 $T$

然后显然我们要按时间拆点,把每天的餐馆拆成早上和晚上,早上送走干净餐巾,晚上得到脏餐巾

每天早上向 $T$ 连一条流量为当天餐巾需求量,费用为 $0$ 的边,如果满流说明当天餐巾够用了

注意餐巾不能就这样流到汇点消失,因为脏餐巾还可以洗了再用,所以从 $S$ 向晚上连一条流量为当天餐巾需求量,费用为 $0$ 的边(要注意源点流到晚上的的餐巾表示的是脏餐巾)

考虑购买餐巾,从 $S$ 连到每天早上,流量为 $INF$,费用为餐巾单价的边

然后考虑快洗,从晚上连一条流量为 $INF$ ,费用为快洗费用的边到对应的时间点的早上

慢洗同理

因为脏餐巾可以留着到下一天,所以每天晚上连到下一天晚上,流量 $INF$ ,费用为 $0$

早上同理

然后跑费用流,注意开 $long\ long$

 

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
using namespace std;
typedef long long ll;
inline int read()
{
    int x=0,f=1; char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); }
    return x*f;
}
const int N=1e5+7,iNF=1e9+7;
const ll INF=1e18+7;
int fir[N],from[N<<2],to[N<<2],val[N<<2],cst[N<<2],cntt=1;
inline void add(int a,int b,int c,int d)
{
    from[++cntt]=fir[a]; fir[a]=cntt;
    to[cntt]=b; val[cntt]=c; cst[cntt]=d;
    from[++cntt]=fir[b]; fir[b]=cntt;
    to[cntt]=a; val[cntt]=0; cst[cntt]=-d;
}
int Nn,S,T;
int mif[N],pre[N];
ll dis[N];
queue <int> q;
bool inq[N];
bool SPFA()
{
    for(int i=1;i<=T;i++) dis[i]=INF;
    q.push(S); inq[S]=1; dis[S]=0; mif[S]=iNF;
    while(!q.empty())
    {
        int x=q.front(); q.pop(); inq[x]=0;
        for(int i=fir[x];i;i=from[i])
        {
            int &v=to[i]; if(!val[i] || dis[v]<=dis[x]+cst[i]) continue;
            dis[v]=dis[x]+cst[i]; pre[v]=i;
            mif[v]=min(mif[x],val[i]);
            if(!inq[v]) q.push(v),inq[v]=1;
        }
    }
    return dis[T]<INF;
}
ll ans;
inline void upd()
{
    for(int now=T,i=pre[T]; now!=S; now=to[i^1],i=pre[now])
        val[i]-=mif[T],val[i^1]+=mif[T];
    ans+=dis[T]*mif[T];
}
//以上为费用流模板
int main()
{
    int a;
    Nn=read(); S=(Nn<<1)+1,T=(Nn<<1)+2;
    for(int i=1;i<=Nn;i++)
    {
        a=read();
        add(S,i,a,0); add(i+Nn,T,a,0);//源点向晚上连,早上向汇点连
    }
    int p,m,f,n,s;
    p=read(),m=read(),f=read(),n=read(),s=read();
    for(int i=1;i<=Nn;i++)
    {
        add(S,i+Nn,iNF,p);//购买餐巾
        if(i+1<=Nn) add(i,i+1,iNF,0),add(i+Nn,i+Nn+1,iNF,0);//时间的转移
        if(i+m<=Nn) add(i,i+Nn+m,iNF,f);//快洗
        if(i+n<=Nn) add(i,i+Nn+n,iNF,s);//慢洗
    }
    while(SPFA()) upd();
    printf("%lld",ans);
    return 0;
}

 

转载于:https://www.cnblogs.com/LLTYYC/p/10351070.html

内容概要:本文档详细介绍了基于MATLAB实现的多头长短期记忆网络(MH-LSTM)结合Transformer编码器进行多变量时间序列预测的项目实例。项目旨在通过融合MH-LSTM对时序动态的细致学习和Transformer对全局依赖的捕捉,显著提升多变量时间序列预测的精度和稳定性。文档涵盖了从项目背景、目标意义、挑战与解决方案、模型架构及代码示例,到具体的应用领域、部署与应用、未来改进方向等方面的全面内容。项目不仅展示了技术实现细节,还提供了从数据预处理、模型构建与训练到性能评估的全流程指导。 适合人群:具备一定编程基础,特别是熟悉MATLAB和深度学习基础知识的研发人员、数据科学家以及从事时间序列预测研究的专业人士。 使用场景及目标:①深入理解MH-LSTM与Transformer结合的多变量时间序列预测模型原理;②掌握MATLAB环境下复杂神经网络的搭建、训练及优化技巧;③应用于金融风险管理、智能电网负荷预测、气象预报、交通流量预测、工业设备健康监测、医疗数据分析、供应链需求预测等多个实际场景,以提高预测精度和决策质量。 阅读建议:此资源不仅适用于希望深入了解多变量时间序列预测技术的读者,也适合希望通过MATLAB实现复杂深度学习模型的开发者。建议读者在学习过程中结合提供的代码示例进行实践操作,并关注模型训练中的关键步骤和超参数调优策略,以便更好地应用于实际项目中。
<template> <div class="product-list"> <div class="product-item" v-for="(item,index)in product" :key="index"> <!-- 店铺信息--> <div class="shop-info"> <span v-if="item.shopType ==='BaiYi'"> <input type="checkbox"/> 百亿补贴品牌优选 </span> <span v-else-if="item.shopType ==='GuoJi'"> <input type="checkbox"/> 国标 {{ item.shopName }} <span v-if="item.hasCoupon" class="coupon-btn">领券></span> </span> <span v-else-if="item.shopType === 'TianMao'"> <input type="checkbox" /> 天猫 {{ item.shopName }} <span v-if="item.hascoupon" class="coupon-btn">领券</span> </span> </div> <div class="product"> <div class="select"> <input type="checkbox"> </div> </div> <div class="p-img"> <img :src="item.img" class="p-img1" alt="图片无法加载"> </div> <div class="p-miaoshu"> <p class="item-title">{{item.title}}</p> <p class="item-title2">{{item.title2}}</p> <p class="item-title3">{{item.title3}}</p> </div> <div class="size"> <div class="size1"> <span>颜色:</span> {{size}} </div> </div> <div class="price"> <span class="huodongjiage">¥{{item.huodongjiage}}</span> <br> <span class="yuanshijiege">¥{{item.yuanshijiage}}</span> </div> <div class="num"> <button class="left">-</button> <input type="text" class="number"> <button class="right">+</button> </div> <div class="p-z"> <span class="in">移入收藏</span> <br> <span class="out">删除</span> </div> </div> </div> </template> <script setup> import {ref} from "vue"; const product = ref([{ img: "https://ts1.tc.mm.bing.net/th?id=OIP-C.Tx0ZWU5KzJhuDRs0OD3tsAHaHa&w=249&h=250&c=8&rs=1&qlt=90&o=6&dpr=1.5&pid=3.1&rm=2", title: "漫花大包纸巾抽纸家用实惠装整箱餐巾纸大尺寸卫生纸批发面巾纸抽", title2: "信用卡支付", title3: "热销爆款,破损包退", size1: "可选择", yuanshijiage: "100", huodongjiage: "9.9", num: "10" }]) </script> <style scoped> </style>为什么我的代码运行前报错
03-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值