-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuva473.cpp
80 lines (59 loc) · 1.29 KB
/
uva473.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
#include <cstdio>
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <limits.h>
#include <list>
using namespace std;
int N, t, M;
int disks[2500];
int memo[21000][2500];
int place(int space_left, int disk_id)
{
if(space_left < 0)
return INT_MIN;
if(memo[space_left][disk_id] != -1)
return memo[space_left][disk_id];
if(disk_id == N - 1)
{
if(space_left - disks[N-1] >= 0)
return memo[space_left][disk_id] = 1;
else
return memo[space_left][disk_id] = 0;
}
int space_curent_disk = space_left % t;
int with_disk;
if(space_curent_disk >= disks[disk_id])
with_disk = 1 + place(space_left - disks[disk_id], disk_id + 1);
else
with_disk = 1 + place(space_left - space_curent_disk - disks[disk_id], disk_id + 1);
int without_disk = place(space_left, disk_id + 1);
int aux = max(with_disk, without_disk);
return memo[space_left][disk_id] = aux;
}
int main()
{
int T; scanf("%d", &T);
for(int k = 1; k <= T; k++)
{
scanf("%d%d%d", &N, &t, &M);
char separator;
for(int i = 0; i < N; i++)
{
cin >> disks[i];
if(i != N - 1)
{
char comma;
cin >> comma;
}
}
memset(memo, -1, sizeof(memo));
int rez = place(M * t, 0);
cout << rez << endl;
if(k != T)
printf("\n");
}
return 0;
}