求序列组合后最大的递增次数

给出n个数,后一个数比前一个数大,count++,问这n个数怎么排列,能使count最大?
全部评论
就是拍个序吧
点赞 回复 分享
发布于 2017-11-18 01:01
上贴想法的 Python 实现 class ListNode(object):     def __init__(self, c):         self.c = c         self.next = None         self.prev = None def max_count(lst): # 返回最大count     if len(lst) <= 1:         return 0     lst.sort() # 创建链表     head = node = ListNode(0)     pre_num = None     for n in lst:         if pre_num == n:             node.c += 1         else:             nnode = ListNode(1)             nnode.prev = node             node.next = nnode             node = nnode         pre_num = n     count = 0     while head.next:         thead = head.next         ncount = 0         while thead:             ncount += 1             thead.c -= 1             nnode = thead.next             del_node(thead)             thead = nnode         count += ncount - 1     return count def del_node(tmp):     if tmp.c == 0:         tmp.prev.next = tmp.next         if tmp.next:             tmp.next.prev = tmp.prev
点赞 回复 分享
发布于 2017-11-17 18:43
对数组进行非递减排序,这样得到的count是最大的吧?
点赞 回复 分享
发布于 2017-11-17 17:03

相关推荐

04-06 16:59
已编辑
河南工业大学 Java
牛牛牛的牛子:最好扔了,实在没有选择的选择
点赞 评论 收藏
分享
野猪不是猪🐗:现在的环境就是这样,供远大于求。 以前卡学历,现在最高学历不够卡了,还要卡第一学历。 还是不够筛,于是还要求得有实习、不能有gap等等... 可能这个岗位总共就一个hc,筛到最后还是有十几个人满足这些要求。他们都非常优秀,各方面都很棒。 那没办法了,看那个顺眼选哪个呗。 很残酷,也很现实
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务