[Luogu P1280] Nick task

P1280 Nick task

A working Nick is N minutes, from the first minute to the end of the N-th minutes. When Nick arrived at work he began to work. If there are multiple tasks to be done, Nick can choose one of them to do, and the rest by his colleagues completed, whereas if only one task, it is necessary to complete the task by Nick at the same time, if some tasks start time Nick is working to complete these tasks by Nick colleagues. If a task P starts at the first minute, the duration is T minutes, then the task to be concluded at P + T-1 minute.

Write a program to calculate how Nick task should be selected in order to get the most spare time.

 

analysis:

DP only consider the relationship optimal results over a certain period of time, and to meet no after-effect.

We will look at this question, if Nick at one point in time did not receive the task, we let him continue his original idle time, idle time idle time = +1 now a free point on; if then there is this task start point in time, we will insert it, there are several such tasks for us to choose the best.

Suppose we start sweeping from time 0, then it is assumed at time t for the event j end time, apparently equation w [t] = max (w [t - v [j]]) does not hold, because the topics condition: "If at the same time a plurality of tasks to be done, one of which may optionally be Nick do. If there is only one task, the task required to complete the Nick. " To push the event end time can not satisfy this condition.

So if we start from the time n sweep it forward? w [t] = max (w [t + v [j]]). Because an event start and end time point of the idle time is the same, so in the event of a start timing, select the longest idle embodiment ,, the final output w [1], the optimal solution can be obtained.

Put core code:

int top = k;
for(int i=n;i>0;i--){
    if(i == v[top].p){
        while(i == v[top].p && top >= 1)
            w[i] = max(w[i],w[i + v[top].t]),top--;
    }
    else w[i] = w[i + 1] + 1;
}    

 

Guess you like

Origin www.cnblogs.com/Cindy-Chan/p/11272274.html