아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

COPS--Cows On Pogo Sticks

면접 대비

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

요약
속도를 한 번에 1만큼만 바꿀 수 있는 포고 점프로 쿠파이를 피해 정확히 길이 L에 도착하는 최소 점프 횟수를 구한다.
난이도

보통10점 중 5점

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

문제

Bessie the Cow wants to use a pogo stick to travel along a cow path of integer length, L. Bessie starts at point 0 and proceeds in integer pogo-jumps to land exactly on point L. Bessie's velocity, V, starts out at zero and is always nonnegative. At the beginning of each bounce, she can change her velocity by -1, 0, or +1. The velocity is the distance Bessie travels along the path during the bounce. Bessie can be traveling at any nonnegative velocity when she lands on point L.

Bessie wishes to avoid jumping on any of the cow pies (small heaps of manure) that happen to be located at various integer points along the path (not including location 1 or location L, of course).

Your job is to determine the smallest number of bounces to reach exactly the end of the path, point L.

EXAMPLE of one legal traversal:

Given L = 18 and Cow pies at 5, 10, 15.

                             1 1 1 1 1 1 1 1 1
locn     0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8
path     +-+-+-+-+-*-+-+-+-+-*-+-+-+-+-*-+-+-+
visited  X X   X     X     X       X         X
velocity  1  2    3    3       4         5

Total number of bounces in example: 6 (Do not count the starting location, as no bounce happened there.)

입력

  • Line 1: two integers: L, N (1 ≤ L ≤ 500, the length of the path,1 ≤ N ≤ 250, the number of cowpies.)
  • Lines 2..N+1: the integer location of a cowpie on the path.

출력

The output is a single line that contains one integer that is the minimum number of bounces for Bessie to pogo-jump down the path and avoid jumping into the cowpies. If there is no way for Bessie to do this, output the integer -1.

예제1

  1. 예제 1

    입력
    18 3
    5
    10
    15
    
    예상 출력
    6