공부, 기록

백준 1405. 미친 로봇 파이썬(PYTHON) 본문

코딩

백준 1405. 미친 로봇 파이썬(PYTHON)

무는빼주세요 2020. 11. 14. 14:28

문제링크 : www.acmicpc.net/problem/1405

 

1405번: 미친 로봇

첫째 줄에 N, 동쪽으로 이동할 확률, 서쪽으로 이동할 확률, 남쪽으로 이동할 확률, 북쪽으로 이동할 확률이 주어진다. N은 14보다 작거나 같은 자연수이고,  모든 확률은 100보다 작거나 같은 자

www.acmicpc.net

 

def solution(num ,percent):
    dx=[1,-1,0,0]
    dy=[0,0,1,-1]
    stack = list()
    visitied = list()
    stack.append((0,0,num,1,[(0,0)]))
    visitied.append((0,0))
    answer=0
    while stack:
        x,y,count,per, path = stack.pop()
        if count == 0:
            answer+=per
            continue
        for i in range(4):
            mx = x+dx[i] ; my = y+dy[i]
            if (mx,my) not in path:
                stack.append((mx,my,count-1,per*percent[i],path+[(mx,my)]))
    return answer
def main():
    NUM, PE, PW, PS, PN = map(int,input().split())
    percent = [PE/100, PW/100, PS/100, PN/100]
    if NUM == 0:
        print(1)
    else:
        print(solution(NUM, percent))

main()