我试图证明 the following algorithm 是完全正确的(部分正确性 + 终止),但我似乎只能证明任意示例输入(不是一般输入)。
Here is my pseudo-code:
IN :Listofjobs J,maxindex n
1:S ← an array indexed 0 to n,with null at each index
2:Sort J in non-increasing order of profits
3:for i from 0 to n
4:Find the largest t such that S[t] = null and t ≤ J[i].deadline (if one exists) if an index t was found
5: S[t] ← J[i]
OUT: S maximizes the profit of scheduled jobs that can be done in n 1 unit of time blocks
例如,我创建了一个包含工作及其相关属性(截止日期和利润)的表:
jOB J1 J2 J3 J4 J5
Deadline 2 1 3 2 1
profit 62 100 20 40 20
从这个示例输入中,我们可以做 J2、J1、J3,总利润为 182。
有人能帮我形成一个更通用的方式来证明我的伪代码算法是完全正确的吗?