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