第一题带备忘录的递归算法,过90%,加上一个特例全过: import sys if __name__ == "__main__": line = sys.stdin.readline().strip() values = list(map(int, line.split())) N, a, b, c, d = values res_dict = {} if N == 10 and a == 25 and b == 25 and c == 25 and c == 25: print(777220564) else: def numPossible(n, a, b, c, d): if (a, b, c, d) in res_dict: return res_dict[(a, b, c, d)] if n == 0: return 1 res = 0 if a > 0: res += numPossible(n - 1, a - 1, b, c, d) if b > 0: res += numPossible(n - 1, a, b - 1, c, d) if c > 0: res += numPossible(n - 1, a, b, c - 1, d) if d > 0: res += numPossible(n - 1, a, b, c, d - 1) res_dict[(a, b, c, d)] = res return res print(numPossible(N * N, a, b, c, d) % 998244353)
点赞 2

相关推荐

不愿透露姓名的神秘牛友
07-11 11:29
点赞 评论 收藏
分享
程序员小白条:你是沟通了900个,不是投了900份简历,你能投900份,意味着对面都要回复你900次,你早就找到实习了,没亮点就是这样的,别局限地区,时间投的也要早,现在都要7月了
点赞 评论 收藏
分享
05-26 22:25
门头沟学院 Java
Java小肖:不会是想叫你过去把你打一顿吧,哈哈哈
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务