#partA:采用穷举法进行规划求解的基本算法
for a in range(0, 2):
for b in range(0, 2):
for c in range(0, 2):
for d in range(0,2):
if a * 6 + b * 4 + c * 5+ d * 8==15:
print(a, b, c, d )
#结果:1,1,1,0
#partB:穷举法进行规划求解的无解案例
# 用Excel是可以做出来的,这里做不出来是因为python的嵌套循环次数需要少于20,
#否则会报错“too many statically nested blocks”,于是我删了一些数据导致规划失败。
for a in range(0, 2):
for b in range(0, 2):
for c in range(0, 2):
for cc in range(0, 2):
for d in range(0, 2):
for e in range(0, 2):
for f in range(0, 2):
for g in range(0, 2):
for h in range(0, 2):
for i in range(0, 2):
for j in range(0, 2):
for k in range(0, 2):
for l in range(0, 2):
for m in range(0, 2):
for n in range(0, 2):
for o in range(0, 2):
for p in range(0, 2):
for q in range(0, 2):
for r in range(0, 2):
if a*38416+b*174760+c*346724+cc*227737+d*54925+e*10980+f*79890+g*81486+h*269940+i*631000+j*398000+k*138390+l*21313+m*43400+n*58160+o*24970+p*25267+q*46134+r*20400==772663:
print(a,b,c,cc,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r)
#结果:无解
转载:https://blog.csdn.net/zhangyingna667/article/details/101637851
查看评论