SlideShare a Scribd company logo
1 of 21
Download to read offline
-
DP 강의 1
서영학
• 알고리즘 4번째 세미나
• ANT (충남대 알고리즘 동아리)
-
DP 1
2
D P란?
• “완전 탐색”에서부터 시작
• 겹치는 부분 기억(저장공간) 하고 쓰기 (불러오기)
• 위치상태에 따라 저장공간 1차원 DP / 2차원 DP / 3차원 DP
• ex) x축 / x, y축 / x, y축 + 상태
• 조건이 모아지는 느낌으로 문제를 분석(sub 함수)
-
DP 1
3
D P란? - 시각화
인자
함수
(알고리즘)
조건!
결과
-
DP 1
4
D P란? - 시각화
인자
함수
(알고리즘)
조건!
결과 기억(저장)
1
-
DP 1
5
D P란? - 시각화
인자
함수
(알고리즘)
조건!
결과 기억(저장)
답
1
I = 1 ~ N
-
DP 1
6
D P란? - 시각화
인자
함수
(알고리즘)
조건!
결과 기억(저장)
답1
2
예외처리
조건!
4
3
I = 1 ~ N
모아지는 느낌의
sub 알고리즘
저장공간 설계
-
DP 1
7
D P란? - 시각화
인자
함수
(알고리즘)
조건!
결과 기억(저장)
답
1
2
예외처리
조건!
4
3
I = 1 ~ N
-
`
8
그럼 문제를 풀어 봅시다.
실전에서 많이 쓰이는 아이디어
-
문제들 – 난이도 중상?
1. 이 친수
https://www.acmicpc.net/problem/2193
2. 쉬운 계단 수
https://www.acmicpc.net/problem/10844
3. 계단 오르기
https://www.acmicpc.net/problem/2579
4. 자두 나무
https://www.acmicpc.net/problem/2240
5. LG 코드 몬스터 1번 문제
6. 내리막길
https://www.acmicpc.net/problem/1520
7. 기타리스트
https://www.acmicpc.net/problem/1520
9
-
DP 1
10
이친수 (예제)
• 0으로 시작하지 않는다
• 1이 두 번 연속 나타나지 않는다.
• 직전이 0에서 온 것
• 직전이 1이세 온 것
• 크로스!
https://www.acmicpc.net/problem/2193
-
DP 1
11
이친수
저장공간
초기 설정
반복 & 저장 & 불러오기
-
DP 1
12
이친수 bottom up
저장공간
초기 설정
반복 & 저장 & 불러오기
-
DP 1
13
이친수 top down
저장공간
재귀 종료 조건
계산 중복 제거 & 앞에 0일 경우 재귀 부르기
계산 중복 제거 & 앞에 1일 경우 재귀 부르기
-
DP 1
14
쉬운 계단 수
• 연속된 숫자들로만 구성
ex) 1012343456
• 가능한 회수를 구함
• 숫자가 가진 특수한 조건
• 저장공간? RGB 거리생각
8
7
6
5
4
3
2
1
9
0
https://www.acmicpc.net/problem/10844
8
7
6
-
DP 1
15
쉬운 계단 수
1. 저장공간? 10공간을
다 담을 수 있도록
2. 예외처리
가. 10진수
나. 첫 시작은 0 아님
3. 값이 모이도록 생각
8
7
6
5
4
3
2
1
9
0
https://www.acmicpc.net/problem/10844
8
7
6
-
DP 1
16
계단 오르기
• 저장공간을 생각해보자
직전에 두 계단 온 경우와
직전에 한 계단씩 온 경우
10
20
15
25
10
20
도착
출발
https://www.acmicpc.net/problem/2579
-
DP 1
17
내리막길
• DP를 이용해 최단 경로는 아니고
• 다음으로 움직이는 케이스들 ?
• 되면 더하기 아니면 패스
https://www.acmicpc.net/problem/1520
-
DP 1
18
자두나무
1. 저장공간? i 값이 홀수? 짝수?
어디서 가져와야 하는지를 생각
(가져올 걸 남겨야 한다.)
- 3차원 배열
2. 예외처리?
3. 값이 모이도록 생각
i= 짝수i= 홀수
https://www.acmicpc.net/problem/2240
-
19
DP 문제
1로 만들기
https://www.acmicpc.net/problem/1463
10
i= 1 i= ni= n/3 i= n/2 i= n-1
-
20
DP 문제
1로 만들기
https://www.acmicpc.net/problem/1463
10
i= 1 i= ni= n/3 i= n/2 i= n-1
-
`
21
질문 있으신가요?

More Related Content

Recently uploaded

Console API (Kitworks Team Study 백혜인 발표자료)
Console API (Kitworks Team Study 백혜인 발표자료)Console API (Kitworks Team Study 백혜인 발표자료)
Console API (Kitworks Team Study 백혜인 발표자료)Wonjun Hwang
 
MOODv2 : Masked Image Modeling for Out-of-Distribution Detection
MOODv2 : Masked Image Modeling for Out-of-Distribution DetectionMOODv2 : Masked Image Modeling for Out-of-Distribution Detection
MOODv2 : Masked Image Modeling for Out-of-Distribution DetectionKim Daeun
 
Merge (Kitworks Team Study 이성수 발표자료 240426)
Merge (Kitworks Team Study 이성수 발표자료 240426)Merge (Kitworks Team Study 이성수 발표자료 240426)
Merge (Kitworks Team Study 이성수 발표자료 240426)Wonjun Hwang
 
캐드앤그래픽스 2024년 5월호 목차
캐드앤그래픽스 2024년 5월호 목차캐드앤그래픽스 2024년 5월호 목차
캐드앤그래픽스 2024년 5월호 목차캐드앤그래픽스
 
A future that integrates LLMs and LAMs (Symposium)
A future that integrates LLMs and LAMs (Symposium)A future that integrates LLMs and LAMs (Symposium)
A future that integrates LLMs and LAMs (Symposium)Tae Young Lee
 
Continual Active Learning for Efficient Adaptation of Machine LearningModels ...
Continual Active Learning for Efficient Adaptation of Machine LearningModels ...Continual Active Learning for Efficient Adaptation of Machine LearningModels ...
Continual Active Learning for Efficient Adaptation of Machine LearningModels ...Kim Daeun
 

Recently uploaded (6)

Console API (Kitworks Team Study 백혜인 발표자료)
Console API (Kitworks Team Study 백혜인 발표자료)Console API (Kitworks Team Study 백혜인 발표자료)
Console API (Kitworks Team Study 백혜인 발표자료)
 
MOODv2 : Masked Image Modeling for Out-of-Distribution Detection
MOODv2 : Masked Image Modeling for Out-of-Distribution DetectionMOODv2 : Masked Image Modeling for Out-of-Distribution Detection
MOODv2 : Masked Image Modeling for Out-of-Distribution Detection
 
Merge (Kitworks Team Study 이성수 발표자료 240426)
Merge (Kitworks Team Study 이성수 발표자료 240426)Merge (Kitworks Team Study 이성수 발표자료 240426)
Merge (Kitworks Team Study 이성수 발표자료 240426)
 
캐드앤그래픽스 2024년 5월호 목차
캐드앤그래픽스 2024년 5월호 목차캐드앤그래픽스 2024년 5월호 목차
캐드앤그래픽스 2024년 5월호 목차
 
A future that integrates LLMs and LAMs (Symposium)
A future that integrates LLMs and LAMs (Symposium)A future that integrates LLMs and LAMs (Symposium)
A future that integrates LLMs and LAMs (Symposium)
 
Continual Active Learning for Efficient Adaptation of Machine LearningModels ...
Continual Active Learning for Efficient Adaptation of Machine LearningModels ...Continual Active Learning for Efficient Adaptation of Machine LearningModels ...
Continual Active Learning for Efficient Adaptation of Machine LearningModels ...
 

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

알고리즘 DP 강의자료

  • 1. - DP 강의 1 서영학 • 알고리즘 4번째 세미나 • ANT (충남대 알고리즘 동아리)
  • 2. - DP 1 2 D P란? • “완전 탐색”에서부터 시작 • 겹치는 부분 기억(저장공간) 하고 쓰기 (불러오기) • 위치상태에 따라 저장공간 1차원 DP / 2차원 DP / 3차원 DP • ex) x축 / x, y축 / x, y축 + 상태 • 조건이 모아지는 느낌으로 문제를 분석(sub 함수)
  • 3. - DP 1 3 D P란? - 시각화 인자 함수 (알고리즘) 조건! 결과
  • 4. - DP 1 4 D P란? - 시각화 인자 함수 (알고리즘) 조건! 결과 기억(저장) 1
  • 5. - DP 1 5 D P란? - 시각화 인자 함수 (알고리즘) 조건! 결과 기억(저장) 답 1 I = 1 ~ N
  • 6. - DP 1 6 D P란? - 시각화 인자 함수 (알고리즘) 조건! 결과 기억(저장) 답1 2 예외처리 조건! 4 3 I = 1 ~ N 모아지는 느낌의 sub 알고리즘 저장공간 설계
  • 7. - DP 1 7 D P란? - 시각화 인자 함수 (알고리즘) 조건! 결과 기억(저장) 답 1 2 예외처리 조건! 4 3 I = 1 ~ N
  • 8. - ` 8 그럼 문제를 풀어 봅시다. 실전에서 많이 쓰이는 아이디어
  • 9. - 문제들 – 난이도 중상? 1. 이 친수 https://www.acmicpc.net/problem/2193 2. 쉬운 계단 수 https://www.acmicpc.net/problem/10844 3. 계단 오르기 https://www.acmicpc.net/problem/2579 4. 자두 나무 https://www.acmicpc.net/problem/2240 5. LG 코드 몬스터 1번 문제 6. 내리막길 https://www.acmicpc.net/problem/1520 7. 기타리스트 https://www.acmicpc.net/problem/1520 9
  • 10. - DP 1 10 이친수 (예제) • 0으로 시작하지 않는다 • 1이 두 번 연속 나타나지 않는다. • 직전이 0에서 온 것 • 직전이 1이세 온 것 • 크로스! https://www.acmicpc.net/problem/2193
  • 12. - DP 1 12 이친수 bottom up 저장공간 초기 설정 반복 & 저장 & 불러오기
  • 13. - DP 1 13 이친수 top down 저장공간 재귀 종료 조건 계산 중복 제거 & 앞에 0일 경우 재귀 부르기 계산 중복 제거 & 앞에 1일 경우 재귀 부르기
  • 14. - DP 1 14 쉬운 계단 수 • 연속된 숫자들로만 구성 ex) 1012343456 • 가능한 회수를 구함 • 숫자가 가진 특수한 조건 • 저장공간? RGB 거리생각 8 7 6 5 4 3 2 1 9 0 https://www.acmicpc.net/problem/10844 8 7 6
  • 15. - DP 1 15 쉬운 계단 수 1. 저장공간? 10공간을 다 담을 수 있도록 2. 예외처리 가. 10진수 나. 첫 시작은 0 아님 3. 값이 모이도록 생각 8 7 6 5 4 3 2 1 9 0 https://www.acmicpc.net/problem/10844 8 7 6
  • 16. - DP 1 16 계단 오르기 • 저장공간을 생각해보자 직전에 두 계단 온 경우와 직전에 한 계단씩 온 경우 10 20 15 25 10 20 도착 출발 https://www.acmicpc.net/problem/2579
  • 17. - DP 1 17 내리막길 • DP를 이용해 최단 경로는 아니고 • 다음으로 움직이는 케이스들 ? • 되면 더하기 아니면 패스 https://www.acmicpc.net/problem/1520
  • 18. - DP 1 18 자두나무 1. 저장공간? i 값이 홀수? 짝수? 어디서 가져와야 하는지를 생각 (가져올 걸 남겨야 한다.) - 3차원 배열 2. 예외처리? 3. 값이 모이도록 생각 i= 짝수i= 홀수 https://www.acmicpc.net/problem/2240