python-过兵卒345测试点超时
查看原帖
python-过兵卒345测试点超时
905369
jzhjzh123楼主2022/12/11 12:09
import sys
sys.setrecursionlimit(100000)
bx,by,mx,my=map(int,input().split())
md=[[mx,my],]
for x in (1,-1):
    for y in (2,-2):
        md.append([mx+x,my+y])
for x in (2,-2):
    for y in (1,-1):
        md.append([mx+x,my+y])

def f(x,y):
    if [x,y]==[0,0]:
        return 1
    elif x<0 or y<0 or [x,y] in md:
        return 0
    else:
        return f(x-1,y)+f(x,y-1)

print(f(bx,by))

用的是递归算法,超时了……

2022/12/11 12:09
加载中...