-
Notifications
You must be signed in to change notification settings - Fork 0
/
ejercicio9.cpp
82 lines (80 loc) · 2.05 KB
/
ejercicio9.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
#ifndef STD_USING_AND_INCLUDES
#define STD_USING_AND_INCLUDES
#include <assert.h>
#include <iostream>
#include <string>
using namespace std;
#endif
void addToMatrix(int ** &matrix, int storage, int gameSize, int gamePop, int gameRow)
{
if(gameRow == 1)
{
for(int j = 1; j <= storage; j++)
{
if(j < gameSize)
{
matrix[gameRow][j] = 0;
}
else
{
matrix[gameRow][j] = gamePop;
}
}
}
else
{
for(int j = 1; j <= storage; j++)
{
if(j < gameSize)
{
int upperCellPop = matrix[gameRow-1][j];
matrix[gameRow][j] = upperCellPop;
}
else
{
int upperCellPop = matrix[gameRow-1][j];
int candidatePop = matrix[gameRow-1][j-gameSize] + gamePop;
if(candidatePop > upperCellPop)
{
matrix[gameRow][j] = candidatePop;
}
else
{
matrix[gameRow][j] = upperCellPop;
}
}
}
}
}
int main()
{
int storage;
cin >> storage;
int actualYear;
cin >> actualYear;
int totalGames;
cin >> totalGames;
// Inicializo una matriz de tamaño [totalGames+1]x[storage+1]. No uso la fila ni la columna 0.
int ** matrix = new int*[totalGames+1];
for(int i = 0; i < totalGames+1; i++)
{
matrix[i] = new int[storage+1];
matrix[i][0] = 0;
}
for(int i = 0; i < totalGames; i++)
{
string _;
cin >> _; // Se descarta el nombre del juego.
int size;
cin >> size;
int popularity;
cin >> popularity;
int year;
cin >> year;
popularity = popularity - 5*(actualYear - year);
popularity = popularity < 0 ? 0 : popularity;
addToMatrix(matrix, storage, size, popularity, i+1);
}
cout << matrix[totalGames][storage] << endl;
return 0;
}