-->
当前位置:首页 > 题库

PROGRAMMING:Car refueling problem

Luz5年前 (2021-05-10)题库475
Title Source: algorithm design and analysis by Wang Xiaodong
A car can run n kilometers with full gas. There are several gas stations on the journey. Design an effective algorithm and point out that it should be improved
At which gas stations do you stop to refuel so as to minimize the number of refuelings along the way.
###Input format:
The first line has two positive integers n and K (k < = 1000), which means that the car can travel n kilometers after filling up with fuel, and there are k gas stations on the journey.
The second line has K + 1 integers, which represents the distance between the kth gas station and the k-1 gas station.
The zero gas station indicates the place of departure, and the car is full of gas.
The K + 1 gas station represents the destination.
###Output format:
Output minimum refueling times. If the destination cannot be reached, output "no solution!".
###Input example:
```in
7 7
1 2 3 4 5 1 6 6
```
###Output example:
```out
four
```







answer:If there is no answer, please comment