Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 백트래킹
- DFS
- 투 포인터
- 재귀
- BFS
- 알고리즘
- 다이나믹 프로그래밍
- 누적 합
- 스택
- ue5
- 그래프
- XR Interaction Toolkit
- 백준
- 시뮬레이션
- 유니티
- 그리디 알고리즘
- 브루트포스
- 자료구조
- Team Fortress 2
- 트리
- c++
- 수학
- 문자열
- 유니온 파인드
- 구현
- 정렬
- Unreal Engine 5
- 다익스트라
- 우선순위 큐
- VR
Archives
- Today
- Total
1일1알
백준 10942번 팰린드롬? C++ 본문
메모이제이션 기법을 이용해서 풀었다.
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
using namespace std;
using int64 = long long;
int n, m;
vector<int> v;
vector<vector<int>> cache;
int DP(int start, int end) {
int& ret = cache[start][end];
if (start >= end)
return ret = 1;
if (cache[start][end] != -1)
return ret;
if (v[start] != v[end])
return ret = 0;
return ret = DP(start + 1, end - 1);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
v = vector<int>(n + 1);
cache = vector<vector<int>>(n + 1, vector<int>(n + 1, -1));
for (int i = 1; i <= n; i++) {
cin >> v[i];
}
cin >> m;
for (int i = 0; i < m; i++) {
int start, end;
cin >> start >> end;
cout << DP(start, end) << "\n";
}
}
'알고리즘' 카테고리의 다른 글
백준 1647번 도시 분할 계획 C++ (0) | 2022.07.09 |
---|---|
백준 7579번 앱 C++ (0) | 2022.07.08 |
백준 1806번 부분합 C++ (0) | 2022.07.03 |
백준 1197번 최소 스패닝 트리 C++ (0) | 2022.07.02 |
백준 2467번 용액 C++ (0) | 2022.07.01 |