#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
const int maxn=1005;
const int inf=1000000000;
int dp[maxn],g[maxn][maxn],n,j,choice[maxn];
int DP(int i){
if(dp[i]>0) return dp[i];
for(int j=0;j<n;j++){
if(g[i][j]!=inf){
int tmp=DP(j)+g[i][j];
if(tmp>dp[i]){
dp[i]=tmp;
choice[i]=j;
}
}
}
return dp[i];//边界返回的是0!!
}
void printpath(int i){ //打印某点开始的最长(关键)路径!
printf("%d",i);
while(choice[i]!=-1){
i=choice[i];
printf("->%d",i);
}
}
int main(){
fill(choice,choice+maxn,-1);
return 0;
}
记录最长路径
最新推荐文章于 2024-07-15 22:10:26 发布