This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def next-move(state, depth): | |
bestMove = nil | |
alpha = -INF | |
for next-state in state.nexts(): | |
result = minscore(next-state, depth-1, alpha, INF) | |
if result > alpha: | |
alpha = result | |
bestMove = next-state.move() | |
if alpha >= MAX-POSSIBLE-SCORE: | |
break |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Evaluation function for Phase 1 = 18 * (1) + 26 * (2) + 1 * (3) + 9 * (4) + 10 * (5) + 7 * (6) | |
Evaluation function for Phase 2 = 14 * (1) + 43 * (2) + 10 * (3) + 11 * (4) + 8 * (7) + 1086 * (8) | |
Evaluation function for Phase 3 = 16 * (1) + 10 * (5) + 1 * (6) + 1190 * (8) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add v to A[p] | |
update(p, v): | |
for (; p <= N; p += p&(-p)) | |
ft[p] += v | |
# Return sum A[1...b] | |
query(b): | |
sum = 0 | |
for(; b > 0; b -= b&(-b)) | |
sum += ft[b] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Let R be the set of all requests | |
Let d = 0 be the number of resources | |
while !R.empty(): | |
Choose a request i ∈ R that has the earliest start time | |
if i can be assigned to some resource k <= d: | |
assign request i to resource k | |
else: | |
allocate a new resource d+1 | |
assign request i to resource d+1 | |
d = d + 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
OPT(j): | |
if j == 0: | |
return 0 | |
return max(wj + OPT(p(j)), OPT(j-1)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sort the n requests in order of start time | |
d = 1 | |
assign request 1 to resource 1 | |
min_pq.insert(1, f(i)) | |
for i = 2 to n: | |
j = min_pq.minIndex() | |
if s(i) >= min_pq.keyOf(j): | |
assign request i to resource j | |
min_pq.increaseKey(j, f(i)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sort the jobs in non-decreasing order of their deadlines | |
last_finished = s[1] | |
for i = 1 to n: | |
Assign job i to the interval [last_finished, last_finished + t[i]] | |
last_finished += t[i] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Let disc_time[v] = -1 and explored[v] = false forall v | |
dfscounter = 0 | |
DFS(v): | |
explored[v] = true | |
disc_time[v] = low[v] = ++dfscounter | |
foreach edge (v,x): | |
if !explored[x]: | |
DFS(x) | |
low[v] = min(low[v], low[x]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Partition(bolts[lo...hi], nut): | |
j = lo | |
for i in range(lo, hi): | |
if bolts[i] < nut: | |
swap(bolts[i], bolts[j]) | |
j += 1 | |
elif bolts[i] == nut: | |
swap(bolts[i], bolts[hi]) | |
# the bolt that ends up at i might be larger than nut | |
i -= 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
OPT[0] = 0 | |
for j = 1 to n: | |
for i = 1 to j: | |
compute e(i, j) for the segment pi, pi+1, ..., pj | |
for j = 1 to n: | |
OPT(j) = min((e(i,j) + C + OPT[i-1]) forall 1 ≤ i ≤ j) | |
return OPT[n] |
OlderNewer