一组数字中最高的塔

20

``````4 2  1 9  6  8
``````

``````2
6
``````

`````` 9
5 8
``````

``````            0
7           1
5    1     1 1         9 supports a total weight of 1.5 = (1+1/2)/2 + (1+1/2)/2
2   5 4    5 5
3  5 9 5  5 6 3        6 supports a total weight of 3 =  1.5 + 1.5 = (2*1+(2*1/2))/2 + (2*1+(2*1/2))/2
``````

``````1         5           The problems with the towers are (from left to right):
1  12    2 3     8      1 can't support 1+1; no space between 1 and 2;
1  5 6  1 1 1   9       1 can't support 1.5 = (1+1/2)/2 + (1+1/2)/2; 8 isn't properly supported (digits at both bottom diagonals or exactly below the 8)
``````

输入值

• 包含至少一个元素的非负一位数字的列表。

输出量

• 单个正整数，即最高可建造塔的高度。
• 您的解决方案必须在一分钟之内在我的计算机上解决任何示例测试用例（我将仅测试关闭的用例。我的PC低于平均水平。）。

例子

``````[0]  =>  1

0

[0, 1, 1, 1, 1, 1]  =>  3

0
1
1 1

[1, 1, 1, 1, 1, 2, 2]  =>  4

1
1
1 1
1 2 2

[0, 0, 2, 2, 2, 2, 2, 5, 5, 5, 7, 7, 9]  =>  9

0
2
2
5
5
5
7
7
9

[1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5]  =>  9

1
2
2
3
4
5
3 3
4 4 4
5 5 5 5

[0, 0, 0, 0, 0, 1, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 5, 5, 5, 5, 7, 7, 9]  =>  11

0
1
2
3
4
5
3 3
4 5
5 5
3 7 3
2 7 9 2

[0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9]  =>  12

0
1
2
3
4
5
6
7
4 5
6 7
8 8
9 9

[0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9]  =>  18

0
1
2
3
4
5
6
7
8
9
5 5
6 6
7 7
4 8 4
3 7 7 3
2 6 8 6 2
2 5 8 8 5 2
3 9 9 9 9 3
``````

赏金

• 输入数字可以是任何非负整数，而不仅仅是数字
• 多位数字与单位数字占据相同的位置
• 多位数字可以支持它们的数值，例如`24`可以支持`24`

1

ThreeFx 2015年

1

MI Wright

3
@MIWright数字表示您可以在数字上堆叠多少重量。但重数量本身始终为1

@MartinBüttner哦，du。谢谢。
MI Wright

Grimmy

10

Python 2-326

``````def S(u,c=0,w=[]):
for(s,e)in[(len(w),lambda w,i:w[i]),(len(w)+1,lambda w,i:.5*sum(([0]+w+[0])[i:i+2]))]:
m=u[:];l=[-1]*s
for n in u:
for i in range(s):
if 0>l[i]and n>=e(w,i):m.remove(n);l[i]=n;break
if([]==l or-1in l)==0:
for r in S(m,c+1,[1+e(w,i)for i in range(s)]):yield r
yield c
print max(S(sorted(input())))``````

2