gpt4 book ai didi

java - 回溯Java

转载 作者:行者123 更新时间:2023-12-02 06:44:00 24 4
gpt4 key购买 nike

我有一个控制医疗办公室议程的系统。如果医生取消当天的预约,我需要使用回溯算法。该算法必须根据患者日程安排的偏好(工作日和时间)将取消的预约重新安排在另一个日期和时间。如果所有取消的约会都被重新安排,它必须返回 true。如果一个或多个失败,则必须重试,直到没有解决方案为止。谁能解释一下我应该如何使用该算法来解决这个问题?或者给我一些有用的链接?我尝试在 google 和此处搜索它,但没有成功。

谢谢!

最佳答案

也许这个伪代码会有所帮助:

boolean schedule (array-of-appointments-to-reschedule, calendar-with-available-times) {
for each possible TIME where array-of-appointments[FIRST] can fit into
calendar-with-available-times {
if (array-of-appointments has only 1 element)
return true; // we've succeeded
success = schedule (array-of-appointments-WITHOUT-the-first-one,
calendar-with-available-time with TIME blocked out);
// this is the backtracking part, we call schedule recursively on the
// _remaining_ appointments, and if we can't fit the rest of the
// appointments, then backtrack and try the next TIME
if (success) return true;
}
return false;
}

这并不能解决所有问题,因为它实际上并没有跟踪成功的结果,但希望它能帮助您入门。

关于java - 回溯Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18838548/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com