-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDIEHARD.cpp
More file actions
48 lines (43 loc) · 907 Bytes
/
Copy pathDIEHARD.cpp
File metadata and controls
48 lines (43 loc) · 907 Bytes
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
#include <iostream>
using namespace std;
int health, armor;
int memo[2001][2001][4];
void refresh_memo()
{
for (int i = 0; i <= 2000; i++)
for (int j = 0; j <= 2000; j++)
for (int k = 0; k <= 3; k++)
memo[i][j][k] = -1;
}
int dp(int h, int a, int c)
{
if (h <= 0 || a <= 0)
return 0;
else if (memo[h][a][c] != -1)
return memo[h][a][c];
else
{
if (c == 1)
memo[h][a][c] = 1 + max(dp(h - 5, a - 10, 2), dp(h - 20, a + 5, 3));
else if (c == 2)
memo[h][a][c] = 1 + max(dp(h + 3, a + 2, 1), dp(h - 20, a + 5, 3));
else
memo[h][a][c] = 1 + max(dp(h - 5, a - 10, 2), dp(h + 3, a + 2, 1));
return memo[h][a][c];
}
}
int main()
{
ios::sync_with_stdio(false);
int t;
cin>>t;
while (t--)
{
cin>>health>>armor;
refresh_memo();
cout<<max(dp(health + 3, armor + 2, 1),
max(dp(health - 5, armor - 10, 2),
dp(health - 20, armor + 5, 3)))<<endl;
}
return 0;
}