Cod sursa(job #2507573)

Utilizator Constantin.Dragancea Constantin Constantin. Data 10 decembrie 2019 15:37:16
Problema Problema Damelor Scor 0
Compilator py Status done
Runda Arhiva educationala Marime 0.46 kb
f = open('damesah.in', 'r')
g = open('damesah.out', 'w')
n = int(f.read())

d1 = [0] * 20
d2 = [0] * 20
col = [0] * 20

def back(row):
    if (row == n):
        return 1
    total = 0
    for i in range(n):
        if (col[i] or d2[i + row] or d1[row - i + n]):
            continue
        col[i] = d2[i + row] = d1[row - i + n] = 1
        total += back(row + 1)
        col[i] = d2[i + row] = d1[row - i + n] = 0
    return total

g.write(str(back(0)))