做法一:直接贪心,按照利润排序,然后直接尽量给每个活动安排到最晚的时间即可。时间复杂度O(n * d)当d都为10000时,很容易超时。由于这题数据比较水,所有贪心未超时。
AC代码
#include #include #include #include #include #include #include #include #include
做法二:先按照利润排序,然后并查集--当某个时间点被占据,它的下一个可用时间点为t - 1,将二者合并即可。复杂度n*logn
AC代码
#include #include #include #include #include #include #include #include #include
做法三:利用优先队列,按照时间从大到小依次放入商品,保证当前的商品的截止期限都大于等于当前时间即可。可以理解为当有多个商品需要在同一天完成优先选择价值最大的。
复杂度O(n * lgn)
AC代码
#include #include #include #include #include #include #include #include #include
如有不当之处欢迎指出!