标签:des style blog class code c
Time Limit: 2000/1000 MS
(Java/Others) Memory Limit: 32768/32768 K
(Java/Others)
Total Submission(s): 1453 Accepted
Submission(s): 500
3 4 1 -1 1 0 2 -2 4 2 3 5 1 -90
1 (0 ,0,8) --> 1 8
3 (-2,1,9) --> 3 9
6 (3,6,11) --> 6 11
在此只算两列,后面的和前面一样
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56 |
#include <iostream> #include <cstdio> #include <cstring> #define M 105 #define INF 0x0f0f0f0f using
namespace std; int c[M][M]; // 存每个方格中有多少钱币 int dp[M][M]; // 当前位置当前状态下最多有多少钱币 void
clr( int
s[][M]){ for ( int
i = 0; i < M; i++){ for ( int
j = 0; j < M; j++){ s[i][j] = -INF; } } } inline
int max( int
a, int b){ return
a>b?a:b;} int
main() { int
t,n,m; scanf ( "%d" ,&t); for ( int
cas = 1; cas <= t; cas++){ clr(c); clr(dp); scanf ( "%d%d" ,&n,&m); for ( int
i = 1; i <= n; i++){ for ( int
j = 1; j <= m; j++){ scanf ( "%d" ,&c[i][j]); } } dp[0][1] = 0; for ( int
i = 1; i <= n; i++){ //计算第一列dp值 dp[i][1] = dp[i-1][1] + c[i][1]; } int
x,y; for ( int
j = 2; j <= m; j++){ for ( int
i = 1; i <= n; i++){ x = dp[i][j-1] + c[i][j]; //单独算第一个 y = x; dp[i][j] = max(dp[i][j],x); for ( int
k = i-1; k >= 1; k--){ //往上计算 x = x + c[k][j]; dp[k][j] = max(dp[k][j],x); } for ( int
k = i+1; k <= n; k++){ //往下计算 y = y + c[k][j]; dp[k][j] = max(dp[k][j],y); } } } printf ( "Case #%d:\n%d\n" ,cas,dp[1][m]); } return
0; } |
2014年百度之星程序设计大赛 - 资格赛 1004 -- Labyrinth,布布扣,bubuko.com
2014年百度之星程序设计大赛 - 资格赛 1004 -- Labyrinth
标签:des style blog class code c
原文地址:http://www.cnblogs.com/ubuntu-kevin/p/3733486.html