题解 | #杨辉三角的变形#

杨辉三角的变形

https://www.nowcoder.com/practice/8ef655edf42d4e08b44be4d777edbf43

尴尬我也超时了,然后看了答案

import sys

num = int(input())

# def get(lst,index):
#     try:
#         if index <0 or index >=len(lst):
#             return 0 

#         return lst[index]
#     except IndexError:
#         return 0

# r = -1

# lst = []
# for i in range(1,num+1):
#     if i==1:
#         lst = [1]
#         continue

#     _lst = []
#     for j in range(i*2-1):
#         res = get(lst,j-2)+get(lst,j-1)+get(lst,j)
#         if i==num and res>0 and res%2==0:
#             r=j+1
#             break
#         _lst.append(res)

#     lst = _lst
# print(r)

# -1 -1 2 3 2 4 2 3 2 4
lst = [2,4,2,3]

if num<3:
    print(-1)
else:
    print(lst[num%4-1])





全部评论

相关推荐

牛客41406533...:回答他在课上学,一辈子待在学校的老教授用三十年前的祖传PPT一字一句的讲解,使用谭浩强红皮书作为教材在devc++里面敲出a+++++a的瞬间爆出114514个编译错误来学这样才显得专业
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务