I don't know why this question is classified into the search Category =!
Similar to the practice of shuita.
/** Tyvj-1084 digital triangle * Mike-W * 2012-3-10 * ===========================*/# include <stdio. h> # include <string. h> # include <string. h> # define max_size 30int f [max_size] [max_size]; int OPT [max_size] [max_size]; int n, x, y; int sum; inline int max (INT E1, int E2) {return E1> E2? E1: E2;} inline int min (INT E1, int E2) {return E1> E2? E2: E1;} int main (void) {# ifndef online_judgefreopen ("in", "r", stdin); # endifint I, j; scanf ("% d ", & N); for (I = 1; I <= N; I ++) for (j = 1; j <= I; j ++) scanf ("% d", F [I] + J); scanf ("% d", & X, & Y); memset (OPT, 0, sizeof (OPT); for (I = 1; I <= N; I ++) for (j = 1; j <= I; j ++) OPT [I] [J] = max (OPT [I-1] [J], OPT [I-1] [J-1]) + F [I] [J]; sum = OPT [x] [Y]; memset (OPT, 0, sizeof (OPT); for (I = N; I> = 1; I --) for (j = 1; j <= I; j ++) OPT [I] [J] = max (OPT [I + 1] [J], OPT [I + 1] [J + 1]) + F [I] [J]; sum + = OPT [x] [Y]; printf ("% d \ n", Sum-f [x] [Y]); Return 0 ;}