求助,66分
查看原帖
求助,66分
178992
Hanghang楼主2020/9/4 21:58
#include<bits/stdc++.h>
using namespace std;

int n,o,t,r,fi[403],to[403],ne[403],wp[403],p,d[403],w[403],s=10000000;
void A(int x,int y,int z)
{
	ne[++p]=fi[x];fi[x]=p;to[p]=y;wp[p]=z;
}
void D(int x)
{
	if(x==n)
	{
	    s=min(s,d[x]);w[n]=0;
	}
	else
	{ 
	for(int i=fi[x];i;i=ne[i])
	{
		if(w[to[i]]==0)
		{
			w[to[i]]=1;
			d[to[i]]=d[x]+wp[i];
			D(to[i]);w[to[i]]=0;
		}
	}
	}
}
int main()
{
	cin>>n;o=1;
	while(o<=n)
	{
		t++;
	    for(int i=o+1;i<=n;i++)
	    {
		    cin>>r;A(t,i,r);
	    }
	    o++;
	}
	w[1]=1;D(1);
	cout<<s<<endl;
	return 0;
}
2020/9/4 21:58
加载中...