-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathalg_4.cpp
More file actions
30 lines (26 loc) · 714 Bytes
/
alg_4.cpp
File metadata and controls
30 lines (26 loc) · 714 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
using namespace std;
int street[1000100], t1, t2, houses[1010], maximum; //global variables are initiated with 0's
int bottom_up(int position, int house){
if(position >= maximum){
return 0;
}
else{
while(houses[house] <= position)
house++;
position = houses[house];
if(street[position] == 0)
street[position] = min(t2+bottom_up(position+t2, house), t1+bottom_up(position+t1, house));
return street[position];
}
}
int main() {
int n, c;
cin >> n >> c >> t1 >> t2;
for(int i=0;i<n;i++){
cin >> houses[i];
}
maximum = houses[n-1]; //last positionition = max
cout << bottom_up(0, 0); //begin from the 0 position and 0 house
return 0;
}