# 书架上的书

12

## 输入值

• 正整数的三元组列表，其中每个三元组定义一本书的高度，宽度和深度。
• 输入列表中至少会有一个三元组。
• 两本书可以沿任意多个维度具有相同的长度。

## 输出量

• 一个正整数，表示服从该规则的书架上可容纳的最大书籍数量。

## 例子

``````(1, 1, 1) =>  1

(5, 2, 5), (1, 3, 5) =>  1

(5, 2, 5), (1, 2, 5) =>  2

(2, 2, 2), (2, 2, 2), (2, 2, 2), (1, 3, 6) =>  3

(1, 2, 5), (1, 3, 5), (1, 2, 8), (1, 2, 5), (7, 7, 7) =>  4

(5, 19, 3), (9, 4, 16), (15, 16, 13), (7, 4, 16), (1, 13, 14), (20, 1, 15), (9, 8, 19), (4, 11, 1) =>  3

(1, 1, 18), (1, 13, 7), (14, 1, 17), (8, 15, 16), (18, 8, 12), (8, 8, 15), (10, 1, 14), (18, 4, 6), (10, 4, 11), (17, 14, 17), (7, 10, 10), (19, 16, 17), (13, 19, 2), (16, 8, 13), (14, 6, 12), (18, 12, 3) =>  5
``````

mbomb007'5

@ mbomb007是的，将“不减少”更改为“不增加”。
randomra'5

Answers:

4

# Python 3：436字节

``````import sys
b=[]
n={}
r=[]
for L in sys.stdin.readlines():z=[int(x)for x in L.split()];r+=[z];z in b or b+=[z]
def l(a,b):return a[0]<=b[0]and a[1]<=b[1]and a[2]<=b[2]
R=range(len(b))
for i in R:
n[i]=[]
for j in R:i!=j and l(b[i],b[j])and n[i]+=[j]
def L(t):
global v;best=0
if t in v:
return v[t]
for s in n[t]:best=max(best,L(s)+1)
v[t]=best+r.count(b[t])-1;return best
m=0
for i in R:v={};m=max(L(i)+1,m)
print(m)
``````

1

isaacg，2015年

3

# Pyth，40个字节

``````KYleolNe.eaK+e+]])olNf.A.eg@YbZeT<Kk]YSQ
``````

``````def num_books(l):
l = sorted(l)
s = []
for i, Y in enumerate(l):
s.append(max([T for T in s[:i]
if all(Y[e] >= t for e, t in enumerate(T[-1]))] + [[]],
key=len) + [Y])
return max(len(u) for u in s)
``````

Python 3版本为177字节，具有明显的特点。只是个小气。
mbomb007

0

# Python 2，231字节

``````from operator import*
from itertools import*
def f(t):
m=1
for l in(sorted(t,key=itemgetter(*o))for o in permutations(range(3))):
c=1
for k in range(len(l)-1):
c+=all(i<=j for i,j in zip(l[k],l[k+1]))
m=max(m,c)
print m``````
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.