The main idea: the Great Wall (regarded as the x positive half axis) has the N place breakage. There is an intelligent repair robot that is known for its initial position and movement speed. Each broken place has a set of parameters (X,c,d), X is the position, C, D means that after the time t repair the damage at the cost of D*t+c. Use a robot to repair the minimum cost of all breakage.
Title Analysis: To the ultimate cost, you can not jump repair, that is, after a period of time has been repaired the damage should be a continuous interval. The definition of DP (I,J,K) indicates the cost of the robot staying at K (0 for the left end, 1 for the right end) after the repair (I,J). The cost of repairing a broken place is not fixed, but it grows linearly with time, so when one or a piece of damage is repaired, the cost of repairing the other breakage can be calculated by adding it to the current state, or as a time-cost for repairing a damaged place. State transfer equation: DP (i,j,1) =min (DP (i,j-1,0) +W1,DP (i,j-1,1) +w2) DP (i,j,0) =min (DP (i+1,j,0) +W3,DP (i+1,j,1) +w4) where W1, W2, W3, W4 for the corresponding time cost and repair cost.
The code is as follows:
# include<iostream># include<cstdio># include<cmath># include<cstring># include< algorithm>using namespace Std;const int n=1005;const double inf=1e30;struct p{int x,c,dlt; BOOL operator < (const P &a) const{return x<a.x; }}; P p[n];int n,v,x;double dp[n][n][2],s[n];d ouble dfs (int l,int r,int k) {if (dp[l][r][k]>-1.0) return dp[l][r][k]; if (l==r) {double T=fabs (double) x (double) p[l].x)/(double) v; DP[L][R][K]=S[N]*T+P[L].C; return dp[l][r][k]; } if (k==0) {double A=dfs (l+1,r,0); Double B=dfs (l+1,r,1); Double t1= (double) (p[l+1].x-p[l].x)/(double) v; Double t2= (double) (p[r].x-p[l].x)/(double) v; Double D=s[l]+s[n]-s[r]; Dp[l][r][k]=min (A+D*T1,B+D*T2) + (double) p[l].c; }else{double A=dfs (l,r-1,0); Double B=dfs (l,r-1,1); Double t1= (double) (p[r].x-p[l].x)/(double) v; Double t2= (double) (p[r].x-p[r-1].x)/(double) v; Double D=S[L-1]+S[N]-S[R-1]; Dp[l][r][k]=min (A+D*T1,B+D*T2) +p[r].c; } return dp[l][r][k];} void Look () {for (int. i=1;i<=n;++i) {for (int j=1;j<=n;++j) printf ("%.lf", dp[i][j][0]); cout<<endl; } cout<<endl; for (int i=1;i<=n;++i) {for (int j=1;j<=n;++j) printf ("%.lf", dp[i][j][1]); cout<<endl; }}int Main () {//freopen ("UVA-1336 Fixing the Great Wall.txt", "R", stdin); while (~SCANF ("%d%d%d", &n,&v,&x)) {if (n+v+x==0) break; for (int i=1;i<=n;++i) scanf ("%d%d%d", &P[I].X,&P[I].C,&P[I].DLT); Sort (p+1,p+n+1); s[0]=0.0; for (int i=1;i<=n;++i) s[i]=s[i-1]+ (double) p[i].dlt; Memset (Dp,-1.0,sizeof (DP)); printf ("%d\n", (int) min (dfs (1,n,0), DFS (1,n,1))); Look (); } return 0;}
UVA-1336 Fixing the Great Wall (interval dp)