B Bamboo and Chocolate Factory analysis
Three lines of the problem, is still dynamic planning, but the range of switching involved more. Relatively easy to expand to the N line of the way is the three-layer cycle, the outer layer is the K-robot, the two layers represent a switchable pipeline
Core DP statement: cost[i][k] = min (Cost[i][k], cost[j][k-1]+t[j][i]+p[i][k])
You can also make a detailed list of all possible route cuts based on the a question and then find the minimum value.
Notice that the subject is different from the meaning of T in question a.
Pseudo code given at the machine
//array starting from 0Const intmaxx=510; p[3][maxx]; t[3][3]; cost[3][maxx];//DP Bodyn=2; M is the input valuevoidResolveintNintM) {Initialize cost to infinity three lines with initial values corresponding to P-values: cost[i][0] = p[i][0]; fork=1: M-1 forI=0:2 forj =0:2Cost[i][k] = min (cost[i][k], cost[j][k-1]+t[j][i]+p[i][k]); End end end finds the minimum value for the last robot in three lines is the desired}
Code
Const intmaxx=510;intp[3][maxx];intt[3][3];intcost[3][maxx];Const intMAX = (1<< -);voidResolve (intNintm) {intI,j; for(i=0; i<n; i++) for(j =0; j<m; J + +) cost[i][j] = MAX; for(intI=0; i<n; i++) cost[i][0] = p[i][0]; for(intK =1; k<m; k++) for(inti =0; i<n; i++) for(intj =0; j<n; J + +) {Cost[i][k] = min (cost[i][k], cost[j][k-1]+t[j][i]+p[i][k]); }intAns =500000000; for(i =0; i<n; i++) {if(cost[i][m-1]<ans) ans = cost[i][m-1]; } printf ("%d\n", ans);}intMain () {intM while(SCANF ("%d", &m)!=eof) {intI,j; for(i =0; i<3; i++) for(j =0; j<m; J + +) scanf ("%d", &p[i][j]); for(i=0; i<3; i++) for(j =0; j<3; J + +) scanf ("%d", &t[i][j]); Resolve (3, m); }}
2016-level algorithm third time on machine-b.bamboo and chocolate Factory