SlideShare a Scribd company logo
1 of 16
문제 풀이
2579 계단 오르기
https://www.acmicpc.net/problem/2579
알고리즘 분류: 다이나믹 프로그래밍
풀이
D[i][0]: i-1 계단에서 i 계단으로 왔을 때 최대 값 (1계단 전에서 점프)
D[i][1]: i-2 계단에서 i 계단으로 왔을 때 최대 값 (2계단 전에서 점프)
Index 0 1 2 3 4 5 6 7
Si 0 0 10 20 15 25 10 20
DP[i][0] 0 0
DP[i][1] 0 0
풀이
D[i][0]: i-1 계단에서 i 계단으로 왔을 때 최대 값 (1계단 전에서 점프)
D[i][1]: i-2 계단에서 i 계단으로 왔을 때 최대 값 (2계단 전에서 점프)
Index 0 1 2 3 4 5 6 7
Si 0 0 10 20 15 25 10 20
DP[i][0] 0 0 10
DP[i][1] 0 0
풀이
D[i][0]: i-1 계단에서 i 계단으로 왔을 때 최대 값 (1계단 전에서 점프)
D[i][1]: i-2 계단에서 i 계단으로 왔을 때 최대 값 (2계단 전에서 점프)
Index 0 1 2 3 4 5 6 7
Si 0 0 10 20 15 25 10 20
DP[i][0] 0 0 10
DP[i][1] 0 0 10
풀이
D[i][0]: i-1 계단에서 i 계단으로 왔을 때 최대 값 (1계단 전에서 점프)
D[i][1]: i-2 계단에서 i 계단으로 왔을 때 최대 값 (2계단 전에서 점프)
Index 0 1 2 3 4 5 6 7
Si 0 0 10 20 15 25 10 20
DP[i][0] 0 0 10 30
DP[i][1] 0 0 10
풀이
D[i][0]: i-1 계단에서 i 계단으로 왔을 때 최대 값 (1계단 전에서 점프)
D[i][1]: i-2 계단에서 i 계단으로 왔을 때 최대 값 (2계단 전에서 점프)
Index 0 1 2 3 4 5 6 7
Si 0 0 10 20 15 25 10 20
DP[i][0] 0 0 10 30
DP[i][1] 0 0 10 20
풀이
D[i][0]: i-1 계단에서 i 계단으로 왔을 때 최대 값 (1계단 전에서 점프)
D[i][1]: i-2 계단에서 i 계단으로 왔을 때 최대 값 (2계단 전에서 점프)
Index 0 1 2 3 4 5 6 7
Si 0 0 10 20 15 25 10 20
DP[i][0] 0 0 10 30 35
DP[i][1] 0 0 10 20
풀이
D[i][0]: i-1 계단에서 i 계단으로 왔을 때 최대 값 (1계단 전에서 점프)
D[i][1]: i-2 계단에서 i 계단으로 왔을 때 최대 값 (2계단 전에서 점프)
Index 0 1 2 3 4 5 6 7
Si 0 0 10 20 15 25 10 20
DP[i][0] 0 0 10 30 35
DP[i][1] 0 0 10 20 25
풀이
D[i][0]: i-1 계단에서 i 계단으로 왔을 때 최대 값 (1계단 전에서 점프)
D[i][1]: i-2 계단에서 i 계단으로 왔을 때 최대 값 (2계단 전에서 점프)
Index 0 1 2 3 4 5 6 7
Si 0 0 10 20 15 25 10 20
DP[i][0] 0 0 10 30 35 50
DP[i][1] 0 0 10 20 25
풀이
D[i][0]: i-1 계단에서 i 계단으로 왔을 때 최대 값 (1계단 전에서 점프)
D[i][1]: i-2 계단에서 i 계단으로 왔을 때 최대 값 (2계단 전에서 점프)
정의에 의해서 DP[3][0] + S[5] = 30 + 25 = 55를 DP[5][1]에 저장한다.
Index 0 1 2 3 4 5 6 7
Si 0 0 10 20 15 25 10 20
DP[i][0] 0 0 10 30 35 50
DP[i][1] 0 0 10 20 25 55
풀이
D[i][0]: i-1 계단에서 i 계단으로 왔을 때 최대 값 (1계단 전에서 점프)
D[i][1]: i-2 계단에서 i 계단으로 왔을 때 최대 값 (2계단 전에서 점프)
Index 0 1 2 3 4 5 6 7
Si 0 0 10 20 15 25 10 20
DP[i][0] 0 0 10 30 35 50 65
DP[i][1] 0 0 10 20 25 55
풀이
D[i][0]: i-1 계단에서 i 계단으로 왔을 때 최대 값 (1계단 전에서 점프)
D[i][1]: i-2 계단에서 i 계단으로 왔을 때 최대 값 (2계단 전에서 점프)
정의에 의해서 DP[4][0] + S[6] = 35 + 10 = 45를 DP[6][1]에 저장한다.
Index 0 1 2 3 4 5 6 7
Si 0 0 10 20 15 25 10 20
DP[i][0] 0 0 10 30 35 50 65
DP[i][1] 0 0 10 20 25 55 45
풀이
D[i][0]: i-1 계단에서 i 계단으로 왔을 때 최대 값 (1계단 전에서 점프)
D[i][1]: i-2 계단에서 i 계단으로 왔을 때 최대 값 (2계단 전에서 점프)
Index 0 1 2 3 4 5 6 7
Si 0 0 10 20 15 25 10 20
DP[i][0] 0 0 10 30 35 50 65 65
DP[i][1] 0 0 10 20 25 55 45
풀이
D[i][0]: i-1 계단에서 i 계단으로 왔을 때 최대 값 (1계단 전에서 점프)
D[i][1]: i-2 계단에서 i 계단으로 왔을 때 최대 값 (2계단 전에서 점프)
정의에 의해서 DP[5][0] + S[7] = 55 + 20 = 75를 DP[7][1]에 저장한다.
Index 0 1 2 3 4 5 6 7
Si 0 0 10 20 15 25 10 20
DP[i][0] 0 0 10 30 35 50 65 65
DP[i][1] 0 0 10 20 25 55 45 75
code
Time Complexity
for문 안 코드가 N번 수행되므로
O(N)
Space Complexity
입력 N에 대하여 2차원 배열 사용
O(N^2)

More Related Content

Featured

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
ThinkNow
 
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
Kurio // The Social Media Age(ncy)
 

Featured (20)

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...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 

백준 2579 계단오르기

  • 1. 문제 풀이 2579 계단 오르기 https://www.acmicpc.net/problem/2579 알고리즘 분류: 다이나믹 프로그래밍
  • 2. 풀이 D[i][0]: i-1 계단에서 i 계단으로 왔을 때 최대 값 (1계단 전에서 점프) D[i][1]: i-2 계단에서 i 계단으로 왔을 때 최대 값 (2계단 전에서 점프) Index 0 1 2 3 4 5 6 7 Si 0 0 10 20 15 25 10 20 DP[i][0] 0 0 DP[i][1] 0 0
  • 3. 풀이 D[i][0]: i-1 계단에서 i 계단으로 왔을 때 최대 값 (1계단 전에서 점프) D[i][1]: i-2 계단에서 i 계단으로 왔을 때 최대 값 (2계단 전에서 점프) Index 0 1 2 3 4 5 6 7 Si 0 0 10 20 15 25 10 20 DP[i][0] 0 0 10 DP[i][1] 0 0
  • 4. 풀이 D[i][0]: i-1 계단에서 i 계단으로 왔을 때 최대 값 (1계단 전에서 점프) D[i][1]: i-2 계단에서 i 계단으로 왔을 때 최대 값 (2계단 전에서 점프) Index 0 1 2 3 4 5 6 7 Si 0 0 10 20 15 25 10 20 DP[i][0] 0 0 10 DP[i][1] 0 0 10
  • 5. 풀이 D[i][0]: i-1 계단에서 i 계단으로 왔을 때 최대 값 (1계단 전에서 점프) D[i][1]: i-2 계단에서 i 계단으로 왔을 때 최대 값 (2계단 전에서 점프) Index 0 1 2 3 4 5 6 7 Si 0 0 10 20 15 25 10 20 DP[i][0] 0 0 10 30 DP[i][1] 0 0 10
  • 6. 풀이 D[i][0]: i-1 계단에서 i 계단으로 왔을 때 최대 값 (1계단 전에서 점프) D[i][1]: i-2 계단에서 i 계단으로 왔을 때 최대 값 (2계단 전에서 점프) Index 0 1 2 3 4 5 6 7 Si 0 0 10 20 15 25 10 20 DP[i][0] 0 0 10 30 DP[i][1] 0 0 10 20
  • 7. 풀이 D[i][0]: i-1 계단에서 i 계단으로 왔을 때 최대 값 (1계단 전에서 점프) D[i][1]: i-2 계단에서 i 계단으로 왔을 때 최대 값 (2계단 전에서 점프) Index 0 1 2 3 4 5 6 7 Si 0 0 10 20 15 25 10 20 DP[i][0] 0 0 10 30 35 DP[i][1] 0 0 10 20
  • 8. 풀이 D[i][0]: i-1 계단에서 i 계단으로 왔을 때 최대 값 (1계단 전에서 점프) D[i][1]: i-2 계단에서 i 계단으로 왔을 때 최대 값 (2계단 전에서 점프) Index 0 1 2 3 4 5 6 7 Si 0 0 10 20 15 25 10 20 DP[i][0] 0 0 10 30 35 DP[i][1] 0 0 10 20 25
  • 9. 풀이 D[i][0]: i-1 계단에서 i 계단으로 왔을 때 최대 값 (1계단 전에서 점프) D[i][1]: i-2 계단에서 i 계단으로 왔을 때 최대 값 (2계단 전에서 점프) Index 0 1 2 3 4 5 6 7 Si 0 0 10 20 15 25 10 20 DP[i][0] 0 0 10 30 35 50 DP[i][1] 0 0 10 20 25
  • 10. 풀이 D[i][0]: i-1 계단에서 i 계단으로 왔을 때 최대 값 (1계단 전에서 점프) D[i][1]: i-2 계단에서 i 계단으로 왔을 때 최대 값 (2계단 전에서 점프) 정의에 의해서 DP[3][0] + S[5] = 30 + 25 = 55를 DP[5][1]에 저장한다. Index 0 1 2 3 4 5 6 7 Si 0 0 10 20 15 25 10 20 DP[i][0] 0 0 10 30 35 50 DP[i][1] 0 0 10 20 25 55
  • 11. 풀이 D[i][0]: i-1 계단에서 i 계단으로 왔을 때 최대 값 (1계단 전에서 점프) D[i][1]: i-2 계단에서 i 계단으로 왔을 때 최대 값 (2계단 전에서 점프) Index 0 1 2 3 4 5 6 7 Si 0 0 10 20 15 25 10 20 DP[i][0] 0 0 10 30 35 50 65 DP[i][1] 0 0 10 20 25 55
  • 12. 풀이 D[i][0]: i-1 계단에서 i 계단으로 왔을 때 최대 값 (1계단 전에서 점프) D[i][1]: i-2 계단에서 i 계단으로 왔을 때 최대 값 (2계단 전에서 점프) 정의에 의해서 DP[4][0] + S[6] = 35 + 10 = 45를 DP[6][1]에 저장한다. Index 0 1 2 3 4 5 6 7 Si 0 0 10 20 15 25 10 20 DP[i][0] 0 0 10 30 35 50 65 DP[i][1] 0 0 10 20 25 55 45
  • 13. 풀이 D[i][0]: i-1 계단에서 i 계단으로 왔을 때 최대 값 (1계단 전에서 점프) D[i][1]: i-2 계단에서 i 계단으로 왔을 때 최대 값 (2계단 전에서 점프) Index 0 1 2 3 4 5 6 7 Si 0 0 10 20 15 25 10 20 DP[i][0] 0 0 10 30 35 50 65 65 DP[i][1] 0 0 10 20 25 55 45
  • 14. 풀이 D[i][0]: i-1 계단에서 i 계단으로 왔을 때 최대 값 (1계단 전에서 점프) D[i][1]: i-2 계단에서 i 계단으로 왔을 때 최대 값 (2계단 전에서 점프) 정의에 의해서 DP[5][0] + S[7] = 55 + 20 = 75를 DP[7][1]에 저장한다. Index 0 1 2 3 4 5 6 7 Si 0 0 10 20 15 25 10 20 DP[i][0] 0 0 10 30 35 50 65 65 DP[i][1] 0 0 10 20 25 55 45 75
  • 15. code
  • 16. Time Complexity for문 안 코드가 N번 수행되므로 O(N) Space Complexity 입력 N에 대하여 2차원 배열 사용 O(N^2)