codeforces. 756 B. Travel Card multiple selected binary transfer dp +

Topic link: https: //codeforces.com/problemset/problem/756/B
subject to the effect:

Fare structure in the following manner. Tickets are divided into three types:
one-way ticket to spend 20 rubles,
a 90-minute ticket required 50 rubles,
ticket one day (1440 minutes) it takes 120 rubles.

Note that, at time t x minutes activation ticket may be used for travel within the range from t to t + x -1 (inclusive). Assuming that all the trip only takes a minute.

In order to simplify the selection of passengers, the system will automatically select the best ticket. After the start of each trip, the system analyzes all previous and current travel itinerary, and these trips select a set of tickets at the lowest total cost. Ranging from the first trip to assume all current trip ticket lowest total cost of a, while the total amount previously charged to b. The system then charged to a passenger - b sum.

You have to write a program for a given trip passengers to calculate the total cost of each post stroke charged to passengers.
Here Insert Picture Description

Idea: Every time you three choices. Then find the optimal transfer (half) based on the selection

#include <bits/stdc++.h>
#define LL long long
using namespace std;
 
int n, a[100010], f[100010];
int main()
{
    scanf("%d", &n);
    for(int i=1; i<=n; i++){
        scanf("%d", &a[i]);
    }
    for(int i=1; i<=n; i++){
        f[i]=f[i-1]+20;
        int p=(lower_bound(a+1, a+n+1, a[i]-89)-a-1);
        f[i]=min(f[i], f[p]+50);
        p=(lower_bound(a+1, a+n+1, a[i]-1439)-a-1);
        f[i]=min(f[i], f[p]+120);
        printf("%d\n", f[i]-f[i-1]);
    }
 
    return 0;
}
Published 374 original articles · won praise 22 · views 20000 +

Guess you like

Origin blog.csdn.net/qq_21433411/article/details/103216010