#include<iostream>
#include<cstdio>
#include<deque>
using namespace std;
deque <int> q;
int r[205][205];
int flag[205];
int dis[205];
int main()
{
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
dis[i]=0x7fffffff/3;
for(int i=1;i<n;i++)
for(int j=i+1;j<=n;j++)
{
scanf("%d",&r[i][j]);
r[j][i]=r[i][j];
}
dis[1]=0;
flag[1]=1;
int sum=0;
int cmt=0;
cmt++;
q.push_front(1);
while(q.empty()==0)
{
int u;
while(q.empty()==0)
{
if(dis[q.front()]*cmt<=sum)
{
u=q.front();
q.pop_front();
cmt--;
sum-=dis[u];
break;
}
else
{
q.push_back(q.front());
q.pop_front();
}
}
for(int i=u+1;i<=n;i++)
{
if(dis[i]>dis[u]+r[u][i])
{
dis[i]=dis[u]+r[u][i];
if(flag[i]==0)
{
cmt++;
sum+=dis[i];
flag[i]=1;
if(q.empty()==1||dis[i]<dis[q.front()])
q.push_front(i);
else q.push_back(i);
}
}
}
}
printf("%d",dis[n]);
return 0;
}
P1359 租用游艇
最新推荐文章于 2023-02-06 22:27:40 发布