Description: The minimum value is actually found from this array. The state equation is: s [I] [j] + = min (s [a] [j + 1], s [B] [j + 1]), s [c] [j + 1]); but it is rare that this is not the case. Instead, it is necessary to find a path that satisfies the minimum coordinate of the line, you can only find # include <cstdio> # include <cstring> int min (int a, int B) {if (a> B) return B; else return a;} from the right to the left ;} int main () {// freopen ("a.txt", "r", stdin); int n, m; int num [15] [1, 105], s [15] [105]; while (scanf ("% d", & n, & m )! = EOF) {memset (num,-1, sizeof (num); for (int I = 1; I <= n; I ++) for (int j = 1; j <= m; j ++) scanf ("% d", & s [I] [j]); for (int j = m-1; j> = 1; j --) for (int I = 1; I <= n; I ++) {int B = I, a, c, d, e =-1; if (I >=2) a = I-1; else a = n; if (I <n) c = I + 1; else c = 1; d = min (s [a] [j + 1], s [B] [j + 1]), s [c] [j + 1]); s [I] [j] + = d; if (d = s [a] [j + 1]) e =; if (d = s [B] [j + 1] & (e =-1 | (e! =-1 & B <e) e = B; if (d = s [c] [j + 1] & (e =-1 | (e! =-1 & c <e) e = c; num [I] [j] = e;} int sum = 100000000, flag = 0; for (int I = 1; I <= n; I ++) if (s [I] [1] <sum) {sum = s [I] [1]; flag = I;} printf ("% d", flag); flag = num [flag] [1]; for (int I = 2; I <= m & flag! =-1; I ++) {printf ("% d", flag); flag = num [flag] [I];} printf ("\ n % d \ n", sum);} return 0 ;}