Poj 2948 Martian mining DP

Source: Internet
Author: User

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 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.