找不出错误点,求大佬帮助
查看原帖
找不出错误点,求大佬帮助
304374
Mamba_ever_out楼主2020/4/29 17:42
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; 
const ll Maxn = 105;
const ll Maxm = 25;
const ll INF = 100000000;
ll Head[Maxm],To[Maxm*2],Next[Maxm*2],Value[Maxm*2],cur;
ll n,m,K,e,d;
ll Dp[Maxn],Dist[Maxm];
bool HaveBaned[Maxn][Maxm];
bool Baned[Maxm];
bool inside[Maxm];
ll read()
{
    ll ch=0,x=0;while(ch=getchar(),ch<'0'||ch>'9');
    while(x=x*10+ch-48,ch=getchar(),ch>='0'&&ch<='9');
    return x;
}
void AddEdge(ll F,ll T,ll V)
{
	cur++;;
	Value[cur] = V;
	To[cur] = T;
	Next[cur] = Head[F];
	Head[F] = cur; 
}
void init()
{
	for(int i=1;i<Maxn;i++)
		Dp[i] = INF;
}
void init1()
{
	for(ll i=1;i<Maxm;i++)
		Baned[i] = false;
}
int SPFA()
{
	queue<ll> q;
	q.push(1);
	inside[1] = true;
	for(ll i=1;i<Maxm;i++) Dist[i] = INF;
	Dist[1] = 0;
	while(!q.empty())
	{
		int x = q.front(); q.pop();
		inside[x] = false;
		for(int i=Head[x];i;i=Next[i])
		{
			int y = To[i];
			if(Baned[y]) continue;
			if(Dist[y] > Dist[x] + Value[i])
			{
				Dist[y] = Dist[x] + Value[i];
				if(!inside[y])
					q.push(y);
				inside[y] = true;
			}
		}
	}
	return Dist[m];
}
int main()
{
	init();	//dp数组初始化 
	n = read();m = read();K = read();e = read();
	for(ll i=1;i<=e;i++)
	{
		int a,b,c;
		a=read();b=read();c=read();
		AddEdge(a,b,c);
		AddEdge(b,a,c);
	}
	cin>>d;
	for(ll i=1;i<=d;i++)
	{
		int a,b,c;
		 a=read();b=read();c=read();
		for(int j=b;j<=c;j++)
			HaveBaned[j][a] = true;	
	} 
	Dp[0] = -K;	
	for(ll i=1;i<=n;i++)
	{
		init1();
		for(ll j=i;j>=1;j--)
		{	//j代表天数 
			for(ll k=1;k<=m;k++)
				if(HaveBaned[j][k]) Baned[k] = true;
			ll ans = SPFA();
			if(ans >=INF) break;
			Dp[i] = min(Dp[i],Dp[j-1] + (i-j+1)*ans+K); 
		}
	}
	cout<<Dp[m];
	return 0;	
} ```
2020/4/29 17:42
加载中...