资源简介
本程序用python实现,采用动态规划算法实现数塔问题,并实现界面,实现10层数塔的输入,走过的路径将采用红色背景显示,输出走过路径的最小值。
代码片段和文件信息
# coding=gbk
import tkinter as tk
import tkinter.messagebox
# 更改背景颜色函数
def color(i j):
if i==0:
if j==0: e1.config(bg=‘red‘)
elif i==1:
if j==0: e2.config(bg=‘red‘)
elif j==1: e3.config(bg=‘red‘)
elif i==2:
if j==0: e4.config(bg=‘red‘)
elif j==1: e5.config(bg=‘red‘)
elif j==2: e6.config(bg=‘red‘)
elif i==3:
if j==0: e7.config(bg=‘red‘)
elif j==1: e8.config(bg=‘red‘)
elif j==2: e9.config(bg=‘red‘)
elif j==3: e10.config(bg=‘red‘)
elif i==4:
if j==0: e11.config(bg=‘red‘)
elif j==1: e12.config(bg=‘red‘)
elif j==2: e13.config(bg=‘red‘)
elif j==3: e14.config(bg=‘red‘)
elif j==4: e15.config(bg=‘red‘)
elif i==5:
if j==0: e16.config(bg=‘red‘)
elif j==1: e17.config(bg=‘red‘)
elif j==2: e18.config(bg=‘red‘)
elif j==3: e19.config(bg=‘red‘)
elif j==4: e20.config(bg=‘red‘)
elif j==5: e21.config(bg=‘red‘)
elif i==6:
if j==0: e22.config(bg=‘red‘)
elif j==1: e23.config(bg=‘red‘)
elif j==2: e24.config(bg=‘red‘)
elif j==3: e25.config(bg=‘red‘)
elif j==4: e26.config(bg=‘red‘)
elif j==5: e27.config(bg=‘red‘)
elif j==6: e28.config(bg=‘red‘)
elif i==7:
if j==0: e29.config(bg=‘red‘)
elif j==1: e30.config(bg=‘red‘)
elif j==2: e31.config(bg=‘red‘)
elif j==3: e32.config(bg=‘red‘)
elif j==4: e33.config(bg=‘red‘)
elif j==5: e34.config(bg=‘red‘)
elif j==6: e35.config(bg=‘red‘)
elif j==7: e36.config(bg=‘red‘)
elif i==8:
if j==0: e37.config(bg=‘red‘)
elif j==1: e38.config(bg=‘red‘)
elif j==2: e39.config(bg=‘red‘)
elif j==3: e40.config(bg=‘red‘)
elif j==4: e41.config(bg=‘red‘)
elif j==5: e42.config(bg=‘red‘)
elif j==6: e43.config(bg=‘red‘)
elif j==7: e44.config(bg=‘red‘)
elif j==8: e45.config(bg=‘red‘)
elif i==9:
if j==0: e46.config(bg=‘red‘)
elif j==1: e47.config(bg=‘red‘)
elif j==2: e48.config(bg=‘red‘)
elif j==3: e49.config(bg=‘red‘)
elif j==4: e50.config(bg=‘red‘)
elif j==5: e51.config(bg=‘red‘)
elif j==6: e52.config(bg=‘red‘)
elif j==7: e53.config(bg=‘red‘)
elif j==8: e54.config(bg=‘red‘)
elif j==9: e55.config(bg=‘red‘)
def cpy():
global var
t=e.get()
# 异常设置
if t==‘‘:
tkinter.messagebox.showerror(title=‘错误‘ message=‘请输入层数‘)
return
# 录入数据
matrix[0][0]=e1.get()
matrix[1][0]=e2.get()
matrix[1][1]=e3.get()
matrix[2][0]=e4.get()
matrix[2][1]=e5.get()
matrix[2][2]=e6.get()
matrix[3][0]=e7.get()
matrix[3][1]=e8.get()
matrix[3][2]=e9.get()
matrix[3][3]=e10.get()
matrix[4][0]=e11.get()
matrix[4][1]=e12.get()
matrix[4]
相关资源
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
- python 连连看小游戏源码
- 基于PyQt5的视频播放器设计
- 一个简单的python爬虫
- csv文件行列转换python实现代码
- Python操作Mysql教程手册
- Python Machine Learning Case Studies
- python获取硬件信息
- 量化交易(附python常见函数的使用方
- python 名字用字排行
评论
共有 条评论