SlideShare a Scribd company logo
1 of 11
문제 풀이
14501 퇴사
https://www.acmicpc.net/problem/14501
풀이
Di: i일 부터 상담을 시작하여 받을 수 있는 ‘최대’ 금액 정보
D[i] <- max(D[i+1], P[i] + D[i + T[i]]
단, i일 부터 상담을 시작했을 때 해당 상담이 퇴사일 전(N)에 끝나는 경우에만 금액을 받을 수 있다.
마지막 날 -> 첫째 날 순서로 Di를 구한다.
그러면 DP[0]에는 전체 상담금액 중 최대 금액이 저장된다.
1일 2일 3일 4일 5일 6일 7일
Ti 3 5 1 1 2 4 2
Pi 10 20 10 20 15 40 200
Di 0
풀이
Di: i일 부터 상담을 시작하여 받을 수 있는 ‘최대’ 금액 정보
1일 2일 3일 4일 5일 6일 7일
Ti 3 5 1 1 2 4 2
Pi 10 20 10 20 15 40 200
Di 0 0
풀이
Di: i일 부터 상담을 시작하여 받을 수 있는 ‘최대’ 금액 정보
1일 2일 3일 4일 5일 6일 7일
Ti 3 5 1 1 2 4 2
Pi 10 20 10 20 15 40 200
Di 15 0 0
풀이
Di: i일 부터 상담을 시작하여 받을 수 있는 ‘최대’ 금액 정보
1일 2일 3일 4일 5일 6일 7일
Ti 3 5 1 1 2 4 2
Pi 10 20 10 20 15 40 200
Di 35 15 0 0
풀이
Di: i일 부터 상담을 시작하여 받을 수 있는 ‘최대’ 금액 정보
1일 2일 3일 4일 5일 6일 7일
Ti 3 5 1 1 2 4 2
Pi 10 20 10 20 15 40 200
Di 45 35 15 0 0
풀이
Di: i일 부터 상담을 시작하여 받을 수 있는 ‘최대’ 금액 정보
위의 정의에 의해서 D[2] 에 들어갈 값은 20이 아니라 45이다.
1일 2일 3일 4일 5일 6일 7일
Ti 3 5 1 1 2 4 2
Pi 10 20 10 20 15 40 200
Di 45 45 35 15 0 0
풀이
Di: i일 부터 상담을 시작하여 받을 수 있는 ‘최대’ 금액 정보
위의 정의에 의해서 D[1]에 들어갈 값은 45 이다.
1일 2일 3일 4일 5일 6일 7일
Ti 3 5 1 1 2 4 2
Pi 10 20 10 20 15 40 200
Di 45 45 45 35 15 0 0
pseudocode
input N
init T[N], P[N]
init DP[N+1]
DP[N] <- 0
for day: 0 to N-1
input time data to T[day]
input price data to P[day]
for day: N-1 to 0
nextDay <- day + T[day] // 해당 day에 상담을 시작했을 때, 다음 상담이 시작되는 날
if nextDay > N
DP[day] <- DP[day+1]
else
DP[day] <- max(DP[day+1], DP[nextDay] + P[day])
print(DP[0])
code
Time Complexity
for문 안 코드가 N번 수행되므로
O(N)
Space Complexity
입력 N에 대하여 1차원 배열 사용
O(N)

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
 

백준 14501 퇴사

  • 2. 풀이 Di: i일 부터 상담을 시작하여 받을 수 있는 ‘최대’ 금액 정보 D[i] <- max(D[i+1], P[i] + D[i + T[i]] 단, i일 부터 상담을 시작했을 때 해당 상담이 퇴사일 전(N)에 끝나는 경우에만 금액을 받을 수 있다. 마지막 날 -> 첫째 날 순서로 Di를 구한다. 그러면 DP[0]에는 전체 상담금액 중 최대 금액이 저장된다. 1일 2일 3일 4일 5일 6일 7일 Ti 3 5 1 1 2 4 2 Pi 10 20 10 20 15 40 200 Di 0
  • 3. 풀이 Di: i일 부터 상담을 시작하여 받을 수 있는 ‘최대’ 금액 정보 1일 2일 3일 4일 5일 6일 7일 Ti 3 5 1 1 2 4 2 Pi 10 20 10 20 15 40 200 Di 0 0
  • 4. 풀이 Di: i일 부터 상담을 시작하여 받을 수 있는 ‘최대’ 금액 정보 1일 2일 3일 4일 5일 6일 7일 Ti 3 5 1 1 2 4 2 Pi 10 20 10 20 15 40 200 Di 15 0 0
  • 5. 풀이 Di: i일 부터 상담을 시작하여 받을 수 있는 ‘최대’ 금액 정보 1일 2일 3일 4일 5일 6일 7일 Ti 3 5 1 1 2 4 2 Pi 10 20 10 20 15 40 200 Di 35 15 0 0
  • 6. 풀이 Di: i일 부터 상담을 시작하여 받을 수 있는 ‘최대’ 금액 정보 1일 2일 3일 4일 5일 6일 7일 Ti 3 5 1 1 2 4 2 Pi 10 20 10 20 15 40 200 Di 45 35 15 0 0
  • 7. 풀이 Di: i일 부터 상담을 시작하여 받을 수 있는 ‘최대’ 금액 정보 위의 정의에 의해서 D[2] 에 들어갈 값은 20이 아니라 45이다. 1일 2일 3일 4일 5일 6일 7일 Ti 3 5 1 1 2 4 2 Pi 10 20 10 20 15 40 200 Di 45 45 35 15 0 0
  • 8. 풀이 Di: i일 부터 상담을 시작하여 받을 수 있는 ‘최대’ 금액 정보 위의 정의에 의해서 D[1]에 들어갈 값은 45 이다. 1일 2일 3일 4일 5일 6일 7일 Ti 3 5 1 1 2 4 2 Pi 10 20 10 20 15 40 200 Di 45 45 45 35 15 0 0
  • 9. pseudocode input N init T[N], P[N] init DP[N+1] DP[N] <- 0 for day: 0 to N-1 input time data to T[day] input price data to P[day] for day: N-1 to 0 nextDay <- day + T[day] // 해당 day에 상담을 시작했을 때, 다음 상담이 시작되는 날 if nextDay > N DP[day] <- DP[day+1] else DP[day] <- max(DP[day+1], DP[nextDay] + P[day]) print(DP[0])
  • 10. code
  • 11. Time Complexity for문 안 코드가 N번 수행되므로 O(N) Space Complexity 입력 N에 대하여 1차원 배열 사용 O(N)