Delivery Driver

면접 대비

시간 제한1초메모리 제한2048 MB

요약
매일 세 도시 중 한 곳을 골라 일하며, 연속한 두 날에 도시가 바뀌면 이동 비용을 내고 총이익을 최대로 만든다.
난이도

보통10점 중 4점

유형
동적 계획법, 배열, 구현
정답자
아직 제출이 없습니다

문제

As a delivery driver for a food delivery service, you can work in one of three different cities each day: Denver, Ft. Collins, or Colorado Springs.

While working for the past few years, you have collected data on your net profit from working in each city and applied a predictive machine learning model that allows you to know exactly how much net profit you can make from working in each city for the next NN days.

The model shows that you can make different amounts of money on each day, depending on the location. Naturally, you want to work in the city where you can make the most money each day. However, driving from one city to the next is not without cost, so in some cases it may be better to stay where you are and make slightly less but not have to drive to a different city.

The cost to drive between cities (c_1c\_1 and c_2c\_2) is given by T(c_1,c_2)T(c\_1, c\_2), a constant representing how costly it is to drive from c_1c\_1 to c_2c\_2. Note that T(c_1,c_2)T(c\_1, c\_2) is always equivalent to T(c_2,c_1)T(c\_2, c\_1).

You want to determine which city to work in on each of the next NN days such that your total net profit across all of the days is maximized. (Net profit is calculated by taking the total earnings and subtracting both the operating costs for each day as well as any transition costs incurred by driving between cities.)

Consider the following example (which describes the first sample input). You are planning for the next 33 days and have calculated the profit you could make in each of the cities as shown in the table below:

CityDay 1Day 2Day 3
Denver\\251$\\78$\\398$
Ft. Collins\\174$\\92$\\410$
Colorado Springs\\148$\\151$\\402$

Further, assuming that \begin{align*} T(\text{Denver}, \text{Ft. Collins}) &= \20, \\\ T(\text{Denver}, \text{Colorado Springs}) &= \\17, \text{and} \\ T(\text{Colorado Springs}, \text{Ft. Collins}) &= \34, \end{align\*} if you choose to work from Denver on day 1,ColoradoSpringsonday, Colorado Springs on day 2anddayand day3, then your total net profit would be: \begin{align\*} P\_\text{total} &= \underbrace{\\251}_\text{Day 11 profit} - \underbrace{\17}\_\text{Denver to Colorado Springs} + \underbrace{\\151}_\text{Day 22 profit} + \underbrace{\402}\_\text{Day 3 profit} = \\787 \end{align*} whereas if you chose to work from Denver on day 11, Colorado Springs on day 22, and Ft. Collins on day 33, then your total net profit would be: \begin{align*} P_\text{total} &= \underbrace{\251}\_\text{Day 1 profit} - \underbrace{\\17}_\text{Denver to Colorado Springs} + \underbrace{\151}\_\text{Day 2 profit} - \underbrace{\\34}_\text{Colorado Springs to Ft. Collins} + \underbrace{\410}\_\text{Day 3 profit} = \\761. \end{align*}

Clearly, the first option is better! Even though it may be tempting to go to Ft. Collins on Day 33, the cost of driving there from Colorado Springs is too great.

Can you write a program which tells you which city to work from for each of the next NN days such that total net profit PP across all of the days is maximized? Note that you can start and end in any city you wish, and the start and end cities do not have to be the same.

입력

The first line contains three, space-separated integers representing the values of T(Denver,Ft. Collins)T (\text{Denver}, \text{Ft. Collins}), T(Denver,Colorado Springs)T (\text{Denver}, \text{Colorado Springs}), and T(Colorado Springs,Ft. Collins)T (\text{Colorado Springs}, \text{Ft. Collins}), respectively.

The next line contains a single integer 2≤N≤1002 \leq N \leq 100, the number of days that you have to plan for.

The next 33 lines contain a list of NN space-separated integers representing the potential profit for the next NN days in Denver, Ft. Collins, and Colorado Springs, respectively.

All monetary numbers will be integers between 00 and 100,000100\\,000.

출력

The first and only line of output is the maximum total net profit PP across all NN days in dollars.

예제3

  1. 예제 1

    입력
    20 17 34
    3
    251 78 398
    174 92 410
    148 151 402
    
    예상 출력
    787
    
  2. 예제 2

    입력
    5 5 5
    3
    6 1 0
    0 5 7
    0 0 0
    
    예상 출력
    13
    
  3. 예제 3

    입력
    2 1 3
    3
    0 2 3
    0 1 0
    10 1 0
    
    예상 출력
    14