일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 109. Convert Sorted List to Binary Search Tree
- Generator
- Convert Sorted List to Binary Search Tree
- 파이썬
- 시바견
- Python Implementation
- t1
- Python
- 밴픽
- concurrency
- Class
- iterator
- DWG
- 315. Count of Smaller Numbers After Self
- kaggle
- 프로그래머스
- data science
- 715. Range Module
- shiba
- Substring with Concatenation of All Words
- 30. Substring with Concatenation of All Words
- 운영체제
- Python Code
- Decorator
- Regular Expression
- Protocol
- LeetCode
- attribute
- 43. Multiply Strings
- 컴퓨터의 구조
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/
LeetCode - The World's Leading Online Programming Learning Platform
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
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 |