Question: a row * Col matrix. Each grid has two kinds of mines, yeyenum and bloggium, and knows the number of them in each grid ., The collection site with bloggium in the Northern Region and yeyenum in the western region. Now you need to install a conveyor belt to the North or to the west on these grids (each grid can have one type ). How many mines can be collected (yeyenum + bloggium )?
Question: note that each grid can only go to the West or north. If a grid is selected to the west, it will all go to the west.
# Include & lt; iostream & gt; using namespace STD; # define n 502 # define max (A, B) (A> B? A: B) int DP [N] [N], North [N] [N], West [N] [N]; int main () {int row, Col, r, C, ye, BL; while (scanf ("% d", & Row, & col) & (row + col) {memset (West, 0, sizeof (West); memset (North, 0, sizeof (North); memset (DP, 0, sizeof (DP); For (r = 1; r <= row; r ++) {for (C = 1; C <= Col; C ++) {scanf ("% d", & Ye ); west [r] [c] = West [r] [C-1] + ye ;}for (r = 1; r <= row; r ++) {for (C = 1; C <= Col; C ++) {scanf ("% d", & BL ); north [r] [c] = North [r-1] [c] + BL ;}for (r = 1; r <= row; r ++) {for (C = 1; C <= Col; C ++) DP [r] [c] = max (West [r] [c] + dp [r-1] [c], north [r] [c] + dp [r] [C-1]);} printf ("% d \ n", DP [row] [col]);} return 0 ;}