-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy path607-Scheduling Lectures.cpp
52 lines (48 loc) · 1.37 KB
/
607-Scheduling Lectures.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <bits/stdc++.h>
using namespace std;
int n,l,c,v;
vector<int> topics;
// state: idx = {num lecture, DI}
vector<pair<int,int>> memo;
pair<int,int> solve(int idx) {
if(idx == n) return {0,0};
if(memo[idx].first != -1) return memo[idx];
int min_lec = INT_MAX;
int min_DI = INT_MAX;
int time_left = l;
for(int i=idx;i<n;i++){
time_left -= topics[i];
if(time_left < 0) break;
int di = 0;
if(time_left==0) di = 0;
else if(time_left<=10) di = -c;
else di = (time_left-10)*(time_left-10);
pair<int,int> sub_res = solve(i+1);
int lec_needed = sub_res.first+1;
di += sub_res.second;
if(lec_needed < min_lec) {
min_lec = lec_needed;
min_DI = di;
} else if(min_lec == lec_needed) {
min_DI = min(min_DI, di);
}
}
return memo[idx] = {min_lec, min_DI};
}
int main() {
int tc=1;
while(scanf("%d",&n),n){
if(tc>1) printf("\n");
scanf("%d %d",&l,&c);
memo.assign(n,{-1,-1});
topics.clear();
for(int i=0;i<n;i++){
scanf("%d",&v);
topics.push_back(v);
}
pair<int,int> res = solve(0);
printf("Case %d:\n",tc++);
printf("Minimum number of lectures: %d\n", res.first);
printf("Total dissatisfaction index: %d\n", res.second);
}
}