-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuva607.cpp
125 lines (92 loc) · 2.29 KB
/
uva607.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <cstdio>
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <limits.h>
#include <list>
using namespace std;
int N, L, C;
int lectures[1200];
int memo[510][1010];
int dis[510][1010];
int sat(int time)
{
if(time == 0)
return 0;
else if(1 <= time && time <= 10)
return -C;
else
return (time - 10) * (time - 10);
}
int place(int space_lecture, int lecture_id)
{
if(space_lecture < 0)
return INT_MAX;
if(memo[space_lecture][lecture_id] != -1)
return memo[space_lecture][lecture_id];
if(lecture_id == N - 1)
{
//cout << space_lecture << endl;
if(space_lecture >= lectures[N-1])
{
dis[space_lecture][N-1] = sat(space_lecture - lectures[N-1]);
//return 1;
}
else
{
dis[space_lecture][N-1] = sat(space_lecture) + sat(L - lectures[N-1]);
//return 1;
}
if(space_lecture < lectures[N-1])
return 1;
else
return 0;
}
int without_extra, with_extra;
without_extra = place(space_lecture - lectures[lecture_id], lecture_id + 1);
with_extra = 1 + place(L - lectures[lecture_id], lecture_id + 1);
if(without_extra < with_extra)
{
//if(dis == -1)
dis[space_lecture][lecture_id] = dis[space_lecture - lectures[lecture_id]][lecture_id + 1];
return memo[space_lecture][lecture_id] = without_extra;
}
if(with_extra < without_extra)
{
//if(dis == -1)
dis[space_lecture][lecture_id] = sat(space_lecture) + dis[L - lectures[lecture_id]][lecture_id + 1];
return memo[space_lecture][lecture_id] = with_extra;
}
if(with_extra == without_extra)
{
int dis_total1 = dis[space_lecture - lectures[lecture_id]][lecture_id + 1];
int dis_total2 = sat(space_lecture) + dis[L - lectures[lecture_id]][lecture_id + 1];
dis[space_lecture][lecture_id] = min(dis_total1, dis_total2);
return memo[space_lecture][lecture_id] = with_extra;
}
}
int main()
{
int k = 1;
while(true)
{
scanf("%d", &N);
if(N == 0)
break;
scanf("%d%d", &L, &C);
for(int i = 0; i < N; i++)
cin >> lectures[i];
memset(dis, -1, sizeof(dis));
memset(memo, -1, sizeof(memo));
int rez = place(0, 0);
if(k != 1)
printf("\n");
cout << "Case " << k << ":" << endl;
cout << "Minimum number of lectures: " << rez << endl;
cout << "Total dissatisfaction index: " << dis[0][0] << endl;
k++;
}
return 0;
}