MAX_A = 15
MAX_B = 24
MAX_DEBUG = 5
products = [
{"name": "Ⅰ", "A_hours": 1, "B_hours": 6, "debug_hours": 1, "profit": 2}, # 假设产品Ⅰ至少使用1小时设备A
{"name": "Ⅱ", "A_hours": 5, "B_hours": 2, "debug_hours": 1, "profit": 1}
]
max_profit = 0
best_plan = {}
for i in range(MAX_A // products[0]["A_hours"] + 1):
for j in range(MAX_B // products[1]["B_hours"] + 1):
# 计算调试时间是否足够
if (i + j) * max(products[0]["debug_hours"], products[1]["debug_hours"]) > MAX_DEBUG:
continue
total_A_hours = i * products[0]["A_hours"] + j * products[1]["A_hours"]
total_B_hours = i * products[0]["B_hours"] + j * products[1]["B_hours"]
if total_A_hours > MAX_A or total_B_hours > MAX_B:
continue
total_profit = i * products[0]["profit"] + j * products[1]["profit"]
if total_profit > max_profit:
max_profit = total_profit
best_plan = {"Ⅰ": i, "Ⅱ": j}
print(f"最优生产计划:产品Ⅰ生产{best_plan['Ⅰ']}件,产品Ⅱ生产{best_plan['Ⅱ']}件")
print(f"最大利润为:{max_profit}元")
print("学号:3025")
标签:4.4,profit,MAX,3025,hours,products,max,total From: https://www.cnblogs.com/tjs200461/p/18509012