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 | 29 | 
| 30 | 
                            Tags
                            
                        
                          
                          - 백준
- baekjoon
- 줄 세우기
- 언리얼엔진5
- Programmers
- Frustum
- TObjectPtr
- NRVO
- directx
- const
- RVO
- GeeksForGeeks
- 팰린드롬 만들기
- IFileDialog
- C
- 티스토리챌린지
- 1563
- RootMotion
- 오블완
- Unreal Engine5
- 프로그래머스
- UnrealEngine5
- winapi
- C++
- 2294
- softeer
- UE5
- UnrealEngine4
- DirectX11
- algorithm
                            Archives
                            
                        
                          
                          - Today
- Total
Game Develop
[Algorithm]Baekjoon 2306번 : 유전자 본문
https://www.acmicpc.net/problem/2306
| 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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | #include <iostream> #include <string> #include <map> #include <vector> #include <algorithm> #include <math.h> #include <queue> #include <functional> #include <sstream> #include <memory.h> #include <deque> #include <set> #include <unordered_map> #include <stack> #include <numeric> #include <climits> #include <bitset> #include <cmath> using namespace std; string s; int dp[501][501]; int dfs(int l, int r) {     if (l >= r) return 0;     int& result = dp[l][r];     if (result != -1) return result;     for (int i = l; i < r; ++i)     {         result = max(result, dfs(l, i) + dfs(i + 1, r));     }     if ((s[l] == 'a' && s[r] == 't') ||         (s[l] == 'g' && s[r] == 'c'))     {         result = max(result, dfs(l + 1, r - 1) + 2);     }     return result; } int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> s;     memset(dp, -1, sizeof(dp));     cout << dfs(0, s.size() - 1); } | cs | 
간만에 푸는 어려운 dp문제... 원하는 인덱스의 문자는 삭제해도 되기때문에, 삭제하면서 뭔가 완전탐색하는건가?
했는데 그런거 없이 그냥 탐색이 가능하다.
위 코드를 이해하려면, l, r 인덱스가 어떤식으로 변화하면서 탐색구간이 변경되어지는지 노트에다가 그려보는게 이해하기 쉽다.
'Algorithm > Baekjoon' 카테고리의 다른 글
| [Algorithm]Baekjoon 6987번 : 월드컵 (0) | 2024.10.17 | 
|---|---|
| [Algorithm]Baekjoon 1577번 : 도로의 개수 (1) | 2024.10.16 | 
| [Algorithm]Baekjoon 2981번 : 검문 (1) | 2024.10.15 | 
| [Algorithm]Baekjoon 1720번 : 타일 코드 (0) | 2024.10.15 | 
| [Algorithm]Baekjoon 21772번 : 가희의 고구마 먹방 (0) | 2024.10.10 | 
 
          