"Enter No of Vertices: " "Enter No of Stages: ": Int Input Int Input
"Enter No of Vertices: " "Enter No of Stages: ": Int Input Int Input
"Enter No of Vertices: " "Enter No of Stages: ": Int Input Int Input
def Get_min(s,n):
min_vertex=0
min=9999
for i in range(n):
if(min>(c[s][i]+cost[i])):
min=c[s][i]+cost[i]
min_vertex=i
return min_vertex
def Forward(n):
global totalcost
totalcost=0
def display( ):
print(" Shortest path is...")
ch=''
for i in range(stages-1):
ch+=str(pa[i]+1)+"--"
ch+=str(n)
print ch
print 'totalcost=', totalcost
for i in range(stages):
print('Enter no of vertices in stage ',i+1)
stage_vertices[i]=int(input(' '))
i=0
j=stage_vertices[0]
k=0
for m in range(stages-1):
for i in range(stage_vertices[m]):
for p in range(stage_vertices[m+1]):
print("Enter cost for " ,k+i+1," to ",j+(p+1),": ")
c[k+i][p+j]=input('')
if c[k+i][p+j]==0:
c[k+i][p+j]=9999
j=j+stage_vertices[m+1]
k=k+stage_vertices[m]
print c
Forward(n)
display( )
N queens
board = []
size=input("enter number of queens")
a= [[0 for x in range(size)] for y in range(size)]
def printSolution():
for i in range(size):
print a[i]
return
def placequeen(row):
if row > size:
print board
printSolution()
else:
for col in range(1, size + 1):
if not danger(row, col):
board.append((row, col))
a[row-1][col-1]=1
placequeen(row + 1)
board.remove((row,col))
a[row-1][col-1]=0
placequeen(1)