일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 시바견
- shiba
- 프로그래머스
- Class
- attribute
- Python Implementation
- 파이썬
- Regular Expression
- Generator
- 30. Substring with Concatenation of All Words
- Decorator
- Protocol
- data science
- 컴퓨터의 구조
- Python
- iterator
- kaggle
- 43. Multiply Strings
- DWG
- Convert Sorted List to Binary Search Tree
- 109. Convert Sorted List to Binary Search Tree
- LeetCode
- 715. Range Module
- Substring with Concatenation of All Words
- 밴픽
- Python Code
- 운영체제
- t1
- concurrency
- 315. Count of Smaller Numbers After Self
Archives
- Today
- Total
Scribbling
[C++] 2d DP table with vector 본문
1937. Maximum Number of Points with Cost
https://leetcode.com/problems/maximum-number-of-points-with-cost/description/
class Solution {
public:
long long maxPoints(vector<vector<int>>& points) {
int m = points.size();
int n = points[0].size();
vector<vector<long long>> dp(m, vector<long long>(n, 0));
for (int i = 0; i < n; i++) {
dp[0][i] = points[0][i];
}
for (int i = 1; i < m; i++) {
vector<long long> lefts(n, 0);
vector<long long> rights(n, 0);
lefts[0] = dp[i - 1][0];
for (int j = 1; j < n; j++) {
lefts[j] = max(lefts[j - 1] - 1, dp[i - 1][j]);
}
rights[n - 1] = dp[i - 1][n - 1];
for (int j = n - 2; j >= 0; j--) {
rights[j] = max(rights[j + 1] - 1, dp[i - 1][j]);
}
for (int j = 0; j < n; j++) {
dp[i][j] = points[i][j] + max(lefts[j], rights[j]);
}
}
return *max_element(dp[m - 1].begin(), dp[m-1].end());
}
};
'Computer Science > C++' 카테고리의 다른 글
[C++] Smart pointers (0) | 2023.09.30 |
---|---|
[C++] 전문가를 위한 C++ - Chapter 2 (1) | 2023.09.21 |
[C++] 전문가를 위한 C++ - Chapter 1 (0) | 2023.09.15 |
[C++] vector<vector<int>> sorting with comparator (0) | 2023.09.07 |
[C++] priority queue (pair<int, pair<int, int>>), minheap (0) | 2023.09.02 |