场景:
如果我有一个包含 4 个负载的数组(a1 a2 a3 a4)
a=[a1 a2 a3 a4] (locations of these loads must be fixed)
a=[1 2 3 3]
我想尝试将数组中的所有值增加到 3。
注意:数组a
不是固定的,可以有任何值0:3
约束:
- 有一个不能违反的优先级数组
- 总增量数限制为 3
给定:
优先级数组v=[1 3 2 1]
——(1 为最高优先级,3 为最低优先级)。
注意:数组v
不是固定的,可以有任何值0:3
使用此优先级数组:
a(1,1)=highest priority
a(1,4)=2nd highest priority
a(1,3)=3rd priority
a(1,2)=lowest priority
实施,我的伪代码试验:
a=[1 2 3 3]
v=[1 3 2 1]
count=3
Check highest priority : a(1,1)
increment by 1
decrement count by 1
count = 2
still less than 3 ? if yes, then increment again until a(1,1)<= 3 AND count >=0
Change highest priority to 5 (so that min(v) will not pick it up)
ans : a=[3 2 3 3] ; v=[5 2 3 3] ; count = 1
Check highest priority : a(1,3)
value >= 3
Change highest priority to 5 (so that min(v) will not pick it up)
skip
ans : a=[3 2 3 3] ; v=[5 2 5 3] ; count = 1
Check highest priority : a(1,4)
value >=3
Change highest priority to 5 (so that min(v) will not pick it up)
skip
ans : a=[3 2 3 3] ; v=[5 2 5 5] ; count = 1
Check highest priority : a(1,2)
increment by 1
decrement count by 1
count = 0
still less than 3 ? if yes, then increment again until a(1,1)<= 3 AND count >=0
Change highest priority to 5 (so that min(v) will not pick it up)
ans = [a1 a2 a3 a4] = [3 3 3 3]
注意:如果达到优先级值 = [1 1 1 1],则a
从左到右优先(我还没有找到更好的方法)
我希望这是有道理的,并且我的伪代码显示了我正在尝试实现的内容。问我是否有不清楚的地方。