Skip to content

Commit

Permalink
1932 DP
Browse files Browse the repository at this point in the history
# 2
  • Loading branch information
goo-gy committed Feb 2, 2022
1 parent d611db9 commit 99d2c9a
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions baekjoon/1932_DP.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include <iostream>
#include <vector>

using namespace std;

int N;
vector<vector<int>> vv_DP;
vector<vector<int>> vv_triangle;

int solution()
{
cin >> N;
vv_DP.resize(N + 1);
vv_triangle.resize(N + 1);
for (int i = 0; i <= N; i++)
{
vv_DP[i].resize(N + 2, 0);
vv_triangle[i].resize(N + 1);
}

for (int i = 1; i <= N; i++)
{
for (int j = 1; j <= i; j++)
cin >> vv_triangle[i][j];
}

for (int i = 1; i <= N; i++)
{
for (int j = 1; j <= N; j++)
{
int prev = max(vv_DP[i - 1][j - 1], vv_DP[i - 1][j]);
vv_DP[i][j] = prev + vv_triangle[i][j];
}
}
int maxSum = 0;
for (int i = 1; i <= N; i++)
{
maxSum = max(maxSum, vv_DP[N][i]);
}
cout << maxSum << "\n";

return 0;
}

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solution();
return 0;
}

0 comments on commit 99d2c9a

Please sign in to comment.