vscode报错,不知为何
  • 板块学术版
  • 楼主after_the_end
  • 当前回复3
  • 已保存回复3
  • 发布时间2020/8/16 11:55
  • 上次更新2023/11/6 20:08:30
查看原帖
vscode报错,不知为何
181566
after_the_end楼主2020/8/16 11:55
#include<bits/stdc++.h>
using namespace std;
#define re register
int n,m,kk,e,head[21],cnt,q[401],h,t,d[211],dp[101];
bool f[101][21],flag[21],now[21];
struct node{
    int next,to,w;
}p[401];
inline void addedge(int u,int v,int w){
    p[++cnt].next=head[u];
    p[cnt].w=w;
    p[cnt].to=v;
    head[u]=cnt;
}
inline void spfa(){
    for(re int i=1;i<=n;++i){
        q[i]=0;
    }
    for(re int i=1;i<=m;++i){
        d[i]=0x3f3f3f3f;
        flag[i]=0;
    }
    q[++t]=1;
    flag[1]=1;
    while(h<t){
        ++h;
        for(re int i=head[q[h]];i!=0;i=p[i].next){
            if(d[p[i].to]>d[q[h]]+p[i].w&&!now[p[i].to]){
                d[p[i].to]=d[q[h]]+p[i].w;
                if(!flag[p[i].to]){
                    flag[p[i].to]=1;
                    q[++t]=p[i].to;
                }
            }
        }
        flag[q[h]]=0;
    }
}
int main(){
    scanf("%d%d%d%d",&n,&m,&kk,&e);
    int u,v,w;
    for(re int i=1;i<=e;++i){
        scanf("%d%d%d",&u,&v,&w);
        addedge(u,v,w);
    }
    int d;
    scanf("%d",&d);
    for(re int i=1;i<=d;++i){
        scanf("%d%d%d",&w,&u,&v);
        for(;u<=v;++u){
            f[u][w]=1;
        }
    }
    for(re int i=1;i<=n;++i){
        dp[i]=0x3f3f3f3f;
    }
    dp[0]=-kk;
    for(re int i=1;i<=n;++i){
        for(re int j=1;j<=m;++j){
            now[j]=0;
        }
        for(re int j=i;j>=1;--j){
            for(re int k=1;k<=m;++k){
                if(f[j][k])now[k]=1;
            }
            spfa();
            if(d[m]==0x3f3f3f3f)break;
            dp[i]=min(dp[i],dp[j]+d[m]*(i-j+1)+kk);
        }
    }
    printf("%d",dp[n]);
    return 0;
}

2020/8/16 11:55
加载中...