int solve(int pos, int prev, int type) { if (pos > n) return 0; int curr = A[pos]; int…
- User
int solve(int pos, int prev, int type) {
codeif (pos > n) return 0; int curr = A[pos]; int ans1 = solve(pos + 1, 0, curr) + (type == 0 and prev == curr ? hot[curr] : cold[curr]); int ans2 = solve(pos + 1, 1, curr) + (type == 1 and prev == curr ? hot[curr] : cold[curr]); return min(ans1, ans2);} This is an easy version of the problem. The constraints of t , n , k are the only difference between versions.
You have a device with two CPUs. You also have k programs, numbered 1 through k , that you can run on the CPUs.
The i -th program (1≤i≤k ) takes coldi seconds to run on some CPU. However, if the last program we ran on this CPU was also program i , it only takes hoti seconds (hoti≤coldi ). Note that this only applies if we run program i multiple times consecutively — if we run program i , then some different program, then program i again, it will take coldi seconds the second time.
You are given a sequence a1,a2,…,an of length n , consisting of integers from 1 to k . You need to use your device to run programs a1,a2,…,an in sequence. For all 2≤i≤n , you cannot start running program ai until program ai−1 has completed.
Find the minimum amount of time needed to run all programs a1,a2,…,an in sequence. fix the dp
- Assistant