forked from IElgohary/Uva-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
11341- Term strategy.cpp
executable file
·69 lines (46 loc) · 1.24 KB
/
11341- Term strategy.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
#include <iostream>
#include <cmath>
#include <cstring>
#include <iomanip>
using namespace std;
// decimal approximation problem
int L [15][105];
int N , M;
int dp [15][105];
int f (int i , int j, int hours )
{
if (hours > M )
return -10e6;
if ( j > M - 1 && i <= N - 1)
return -10e6;
if ( i > N - 1 && j > M - 1 )
return 0;
if ( dp[i][hours] != -1)
return dp[i][hours];
int leave = f(i , j+1 ,hours);
int take = -10e6;
if ( L[i][j] >= 5)
take = f(i+1 , 0, hours + j + 1) + L[i][j];
return dp[i][hours] = max(leave , take);
}
int main ()
{
int T;
cin >> T;
while (T--)
{
cin >> N >> M;
memset(L , 0 , sizeof L);
for ( int i = 0 ; i < N ; i++)
for ( int j = 0 ; j < M ; j++)
cin >> L[i][j];
memset(dp , -1 , sizeof dp);
double out = f (0, 0 , 0);
double avg = out / N ;
if (avg >= 5)
cout << "Maximal possible average mark - " <<fixed << setprecision(2) << avg <<"."<< endl;
else
cout << "Peter, you shouldn't have played billiard that much." << endl;
}
return 0;
}