# 第三题:给定一组书的长宽,并且只有当一本书的长宽同时小于另一本书的长宽时,两书才能叠放在一起,求改组书中最多能有多少本书叠放在一起 # 输入:[[20,16],[15,11],[10,10],[9,10]] # 输出:3,前三本可叠放在一起 # L1 = [[20,19],[15,11],[10,116],[10,117],[9,116],[10,10],[9,18],[9,9]] L1 = [[20, 19], [15, 11], [12, 18],[11, 170],[11, 17], [10, 10], [9, 116], [9, 18], [9, 9]] # L1 = [[20,16],[15,11],[10,10],[9,10]]
# 第三题:给定一组书的长宽,并且只有当一本书的长宽同时小于另一本书的长宽时,两书才能叠放在一起,求改组书中最多能有多少本书叠放在一起
# 输入:[[20,16],[15,11],[10,10],[9,10]]
# 输出:3,前三本可叠放在一起
# L1 = [[20,19],[15,11],[10,116],[10,117],[9,116],[10,10],[9,18],[9,9]]
L1 = [[20, 19], [15, 11], [12, 18],[11, 170],[11, 17], [10, 10], [9, 116], [9, 18], [9, 9]]
# L1 = [[20,16],[15,11],[10,10],[9,10]]
L1.sort(reverse=True)
print(L1)
L2 = []
for i in range(len(L1)-1): #上面数变换
k = 0
b = L1[i]
for j in range(i+1,len(L1)):
if b[0] > L1[j][0] and b[1] > L1[j][1]:
k = 0
a = L1[j]
k += 1
for q in range(j+1,len(L1)):
if a[0] > L1[q][0] and a[1] > L1[q][1]:
k +=1
a = L1[q]
L2.append(k)
print(L2)
print(max(L2)+1)