1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #include <iostream> #include <algorithm> using namespace std; int candy[1002][1002]; int d[1002][1002]; int r,c; int main() { cin >> r >> c; for (int i = 1;i <= r; ++i) for (int j = 1; j <= c; ++j) { cin >> candy[i][j]; } for (int i = 1; i <= r; ++i) for (int j = 1; j <= c; ++j) { d[i][j] = max(max(d[i - 1][j], d[i - 1][j - 1]), d[i][j - 1]) + candy[i][j]; } cout << d[r][c] << endl; return 0; } | cs |
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 | #include <iostream> #include <algorithm> using namespace std; int candy[1002][1002]; int d[1002][1002]; int r,c; int main() { cin >> r >> c; for (int i = 1;i <= r; ++i) for (int j = 1; j <= c; ++j) { cin >> candy[i][j]; } d[1][1] = candy[1][1]; for (int i = 1; i <= r; ++i) for (int j = 1; j <= c; ++j) { if (i + 1 <= r && d[i + 1][j] < d[i][j] + candy[i + 1][j]) d[i + 1][j] = d[i][j] + candy[i + 1][j]; if (j + 1 <= c && d[i][j+1] < d[i][j] + candy[i][j+1]) d[i][j + 1] = d[i][j] + candy[i][j + 1]; if (j + 1 <= c && i + 1 <= r && d[i + 1][j + 1] < d[i][j] + candy[i + 1][j + 1]) d[i + 1][j + 1] = d[i][j] + candy[i + 1][j + 1]; } cout << d[r][c] << endl; return 0; } | cs |
'백준 온라인 저지' 카테고리의 다른 글
백준 10942: 팰린드롬? (0) | 2018.07.31 |
---|---|
백준 1890: 점프 (0) | 2018.07.31 |
백준 2263: 트리의 순회 (0) | 2018.07.31 |
백준 1931: 회의실 배정 (0) | 2018.07.30 |
백준 11047: 동전 0 (0) | 2018.07.30 |