标签:
1 #include<iostream> 2 #include<cstring> 3 #include<algorithm> 4 5 using namespace std; 6 7 const int maxn=104; 8 const int inf=0x3f3f3f; 9 10 11 bool vis[maxn][maxn]; //标记2个点是否有路 12 int dp[maxn]; //表示从1到i的最大值 13 int pre[maxn]; 14 int poi[maxn]; 15 16 void output(int cnt) 17 { 18 if(pre[cnt]!=-1) 19 output(pre[cnt]); 20 cout<<cnt<<"->"; 21 } 22 23 int main() 24 { 25 int test; 26 int cas=1; 27 28 cin>>test; 29 30 while(test--) 31 { 32 int n; 33 cin>>n; 34 35 for(int i=1;i<=n;i++) 36 cin>>poi[i]; 37 38 int m; 39 cin>>m; 40 41 memset(vis,false,sizeof(vis)); 42 43 for(int i=1;i<=m;i++) 44 { 45 int u,v; 46 cin>>u>>v; 47 48 vis[u][v]=vis[v][u]=true; 49 } 50 51 poi[n+1]=inf; 52 memset(dp,0,sizeof(dp)); 53 memset(pre,-1,sizeof(pre)); 54 55 for(int i=1;i<=n+1;i++) 56 for(int j=1;j<i;j++) 57 { 58 if(vis[i][j]&&dp[i]<dp[j]+poi[i]) 59 { 60 dp[i]=dp[j]+poi[i]; 61 pre[i]=j; 62 } 63 } 64 65 if(cas>1) 66 cout<<"\n"; 67 68 cout<<"CASE "<<cas++<<"#"<<endl; 69 cout<<"points : "<<dp[n+1]-poi[n+1]<<endl; 70 cout<<"circuit : "; 71 output(pre[n+1]); 72 cout<<1<<endl; 73 } 74 return 0; 75 }
标签:
原文地址:http://www.cnblogs.com/-maybe/p/4447975.html