E - Optimal Slots
The main hall of your residency is open for use by the local community and public. Since it was built on public donations, there is no charge of using it. Every weekend particularly on public holidays there are up to 50 reservations to use it for multiple events with different durations.
You have been assigned by the residents to develop a program in choosing events to get most out of allocation time per weekend and have as short unused time as possible. Program should find the event(s) which fill(s) the allocation time best and print it in the same sequence as appears in the reservation list.
Input
Each test case consist of a single line.
The line starts with two integer T and N which is the time allocated for the hall to be used in the particular weekend and the number of events. The next T integer are the durations of the events (as appear in the reservation list). For example from the first line in sample data: T=5 hours, N, number of events =5, first event lasts for 1 hour, second is 2 hours, third is 3 hours, fourth is 4 hours, and the last one is 5 hours.
The input process will be terminated by a line containing 0.
Output
For each line of input value, in a single line, first, output a list of integers which are the selected events duration and another integer which is the sum of the selected events duration.
If there are multiple possible list of events, events that appear earlier in the list takes priority.
题解:
江哥给我说的要字典序最小,所以当时也没想太多。尬笑.jpg。思路就是从后往前拿,后面尽可能拿价值大的这样才能保证字典序最小。然后从前往后判断路径的时候看是不是那个状态转移过来的就好了。是的话就直接打印出来。
#include <bits/stdc++.h>
#define int long long
using namespac