Hdu 2391 (Water DP)

Source: Internet
Author: User

Simple water DP, an oblique number tower.

The state transfer formula is: map [x] [y] = Max (map [x-1] [y] + map [x] [y], map [x] [Y-1] + map [x] [y]); a point in the question can be directly directed to its oblique vertex, however, you do not need to consider this situation during computing. Therefore, the vertex values are non-negative. Since we can take two steps, why should we take one step ?! Take one more step to pick up a grid of gold.

At the first submission, I forgot that each test instance was followed by a blank line and PE.


[Cpp] # include <stdio. h>
# Include <string. h>
# Define N 1005
Int map [N] [N];
Int Max (int x, int y)
{
Return x> y? X: y;
}
Int main ()
{
Int T;
Int m, n;
Int I, j;
Scanf ("% d", & T );
Int count = 1;
While (T --)
{
Scanf ("% d", & n, & m );
For (I = 0; I <= n + 1; I ++)
{
For (j = 0; j <= m + 1; j ++)
Map [I] [j] = 0;
}
For (I = 1; I <= n; I ++)
{
For (j = 1; j <= m; j ++)
Scanf ("% d", & map [I] [j]);
}
I = 1, j = 1;
Int x, y;
While (I <= n & j <= m)
{
X = I, y = j;
While (x> = 1 & y <= m)
{
Map [x] [y] = Max (map [x-1] [y] + map [x] [y], map [x] [Y-1] + map [x] [y]);
X --;
Y ++;
}
If (I <n)
I ++;
Else
J ++;
}
Printf ("Scenario # % d: \ n", count ++ );
Printf ("% d \ n", map [n] [m]);
Printf ("\ n ");
}
Return 0;
}

# Include <stdio. h>
# Include <string. h>
# Define N 1005
Int map [N] [N];
Int Max (int x, int y)
{
Return x> y? X: y;
}
Int main ()
{
Int T;
Int m, n;
Int I, j;
Scanf ("% d", & T );
Int count = 1;
While (T --)
{
Scanf ("% d", & n, & m );
For (I = 0; I <= n + 1; I ++)
{
For (j = 0; j <= m + 1; j ++)
Map [I] [j] = 0;
}
For (I = 1; I <= n; I ++)
{
For (j = 1; j <= m; j ++)
Scanf ("% d", & map [I] [j]);
}
I = 1, j = 1;
Int x, y;
While (I <= n & j <= m)
{
X = I, y = j;
While (x> = 1 & y <= m)
{
Map [x] [y] = Max (map [x-1] [y] + map [x] [y], map [x] [Y-1] + map [x] [y]);
X --;
Y ++;
}
If (I <n)
I ++;
Else
J ++;
}
Printf ("Scenario # % d: \ n", count ++ );
Printf ("% d \ n", map [n] [m]);
Printf ("\ n ");
}
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.