Created
September 18, 2023 03:47
-
-
Save cjnghn/d4e96636704de1da691049e650fc595e to your computer and use it in GitHub Desktop.
2주차 학습
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int board[105][105]; | |
int dp[105][105]; | |
int main() { | |
cin.tie(0); | |
ios::sync_with_stdio(0); | |
int n; | |
cin >> n; | |
for (int i = 1; i <= n; i++) | |
for (int j = 1; j <= n; j++) | |
cin >> board[i][j]; | |
// Init | |
dp[1][1] = board[1][1]; | |
for (int i = 2; i <= n; i++) { | |
dp[i][1] = dp[i - 1][1] + board[i][1]; | |
dp[1][i] = dp[1][i - 1] + board[1][i]; | |
} | |
// DP | |
for (int i = 2; i <= n; i++) | |
for (int j = 2; j <= n; j++) | |
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) + board[i][j]; | |
cout << dp[n][n] << '\n'; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment