Channel
Idea: Dp[i][j][k]:k, A to I line, B to J of the maximum value of the row
Code:
#include <cstdio>#include<vector>using namespacestd;intMaxPath (vector<vector<int> > &num) { Const intm =num.size (); Const intn = num[0].size (); Const intL = m + N-1; Vector<vector<int> > g (M +1, vector<int> (M +1)); Vector<vector<int> > H (M +1, vector<int> (M +1)); for(intK =1; K <= L; k++) { intst = k <= n?1: K-n +1; inted = k <= m?k:m; for(inti = st; I <= ed; i++) for(intj = i; J <= Ed; J + +) {H[i][j]= Num[i-1][k-i] +max (max (G[i-1][j-1], G[i-1][J]), Max (G[i][j-1], g[i][j]); if(I! =j) H[i][j]+ = Num[j-1][k-J]; } Swap (g, h); } returng[m][m];}intMain () {intm, N; scanf ("%d%d", &m, &N); Vector<vector<int> > num (N, vector<int>(m)); for(inti =0; I < n; i++) for(intj =0; J < M; J + +) scanf ("%d", &Num[i][j]); printf ("%d\n", MaxPath (num)); return 0;}
View Code
"Dynamic planning" 51nod 1084 matrix round-trip fetching number