Next Permutation
Aim: Find a larger permutation
We must move a larger number forward. So we should go from the tail to find any new number is smaller than a number behind it. If no next permutation, reverse list.
Aim: Find a larger permutation
We must move a larger number forward. So we should go from the tail to find any new number is smaller than a number behind it. If no next permutation, reverse list.
24 game is an arithmetic game with a simple rule: Given 4 numbers and use + - * / to get 24.
1, 2, 3, 4
, and you find 1*2*3*4=24
5, 5, 5, 1
, the answer is 5*(5-(1/5))=24
, which includes fractions.24game project provides a powerful C++ solver for the 24 game. And you can play with the PyQt5 based graphical front end.
def maxsum(l):
'''最大子序列和问题'''
m=s=0
for i in l:
s=max(s, 0)
s+=i
m=max(m, s)
return m
def maxprod(l):
'''最大子序列积问题'''
m=pos=0
neg=0
for i in l:
pos=max(1, pos)*i
neg=neg*i
if i<0:
pos, neg=neg, pos
m=max(m, pos)
return m