题目:
链接:点击打开链接
题意:
思路:
代码:
#include <iostream> #include <cstdio> #include <cstring> 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<i; j++) { if(map[j][i] != -1 && dp[j] + map[j][i] > 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; }
收获:
-----------------------------------------------------------------
战斗,从不退缩;奋斗,永不停歇~~~~~~~~~~
hdu 1224 Free DIY Tour(dp),布布扣,bubuko.com
原文:http://blog.csdn.net/u013147615/article/details/32334707