Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
41
Task/N-queens-problem/FreeBASIC/n-queens-problem-2.basic
Normal file
41
Task/N-queens-problem/FreeBASIC/n-queens-problem-2.basic
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
Sub aux(n As Integer, i As Integer, a() As Integer, _
|
||||
u() As Integer, v() As Integer, ByRef m As LongInt)
|
||||
|
||||
Dim As Integer j, k, p, q
|
||||
If i > n Then
|
||||
m += 1
|
||||
For k = 1 To n : Print a(k); : Next : Print
|
||||
Else
|
||||
For j = i To n
|
||||
k = a(j)
|
||||
p = i - k + n
|
||||
q = i + k - 1
|
||||
If u(p) And v(q) Then
|
||||
u(p) = 0 : v(q) = 0
|
||||
a(j) = a(i) : a(i) = k
|
||||
aux(n, i + 1, a(), u(), v(), m)
|
||||
u(p) = 1 : v(q) = 1
|
||||
a(i) = a(j) : a(j) = k
|
||||
End If
|
||||
Next
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Dim As Integer n, i
|
||||
Dim m As LongInt = 1
|
||||
If Command(1) <> "" Then
|
||||
n = CInt(Command(1))
|
||||
ReDim a(1 To n) As Integer
|
||||
ReDim u(1 To 2 * n - 1) As Integer
|
||||
ReDim v(1 To 2 * n - 1) As Integer
|
||||
For i = 1 To n
|
||||
a(i) = i
|
||||
Next
|
||||
For i = 1 To 2 * n - 1
|
||||
u(i) = 1
|
||||
v(i) = 1
|
||||
Next
|
||||
m = 0
|
||||
aux(n, 1, a(), u(), v(), m)
|
||||
Print m
|
||||
End If
|
||||
Loading…
Add table
Add a link
Reference in a new issue