Exercises
First think F[l][i][j][k], indicating the sequence L, the minimum cost of three drivers at i,j,k points
Then obviously the order of I, J, K doesn't matter.
Then obviously I, J, K has a position in the sequence L term represents.
Then we can shrink one dimension.
Set the sequence L to To[l],
The state becomes F[i][j][k] represents three drivers respectively in the to[i],j,k.
Because the order does not matter, we can also define J constant <=k to the card constant.
Then 1000 of cubic space is too large.
Simple analysis discovers that state transitions allow the use of scrolling arrays.
So scroll a little bit more.
Last Space complexity O (n^2),
The bottleneck is the path length and state, with a constant of 3
Time complexity O (m*n*n), where M is the number of appointment locations
The bottleneck is the state transition, which is 3 * 1/2 =1.5
Then the violence can be bzoj on the card.
>,< can not go down will be the questions, to the water ....
Post code:
#include <cstdio> #include <cstring> #include <algorithm> #define N 1050#define inf 0x3f3f3f3fusing namespace Std;int map[n][n],n;int f[2][n][n],now,last;int to[n],m;int Main () {//freopen ("test.in", "R", stdin); int i,j, K;SCANF ("%d", &n), for (i=1;i<=n;i++) for (j=1;j<=n;j++) scanf ("%d", &map[i][j]) and while (scanf ("%d",& TO[++M])!=eof); Now=0,last=1;memset (F,0x3f,sizeof (f)); f[now][1][2]=map[3][to[1]];f[now][1][3]=map[2][to[1]];f[ Now][2][3]=map[1][to[1]];for (i=2;i<m;i++) {Now^=1,last^=1;memset (f[now],0x3f,sizeof (F[now])); for (j=1;j<=n ; j + +) {for (k=j;k<=n;k++) {//to[i-1]f[now][j][k]=f[now][k][j]=min (f[now][j][k],f[last][j][k]+map[to[i-1]][to[i ]]);//jf[now][to[i-1]][k]=f[now][k][to[i-1]]=min (F[now][to[i-1]][k],f[last][j][k]+map[j][to[i]);//kf[now][to[ I-1]][j]=f[now][j][to[i-1]]=min (F[now][to[i-1]][j],f[last][j][k]+map[k][to[i]);}} int Ans=inf;for (i=1;i<=n;i++) for (j=i;j<=n;j++) ans=min (Ans,f[now][i][j]);p rintf ("%d\n", ans); return 0;}
"BZOJ1820" "JSOI2010" express service delivery violence DP