題目:
鏈接:點擊打開鏈接
題意:
思路:
代碼:
#include#include #include using namespace std; int map[110][110]; int dp[110],next[110],ins[110]; int t,n,m; void output(int x) { if(x == -1) return ; output(next[x]); printf("%d->",x); } void ddpp() { for(int i=1; i<=n+1; i++) { for(int j=1; j dp[i]) { dp[i] = dp[j] + map[j][i]; next[i] = j; } } } } int main() { //freopen("input.txt","r",stdin); int a,b; int kase = 1; cin>>t; while(t--) { scanf("%d",&n); memset(map,-1,sizeof(map)); memset(dp,0,sizeof(dp)); for(int i=1; i<=n; i++) { scanf("%d",&ins[i]); } ins[n+1] = 0; scanf("%d",&m); for(int i=1; i<=m; i++) { scanf("%d%d",&a,&b); map[a][b] = ins[b]; } next[1] = -1; ddpp(); if(kase > 1) printf("\n"); printf("CASE %d#\n",kase++); printf("points : %d\n",dp[n+1]); printf("circuit : "); output(next[n+1]); printf("1\n"); } return 0; }
收獲:
-----------------------------------------------------------------
戰斗,從不退縮;奮斗,永不停歇~~~~~~~~~~