Created
May 5, 2015 01:26
-
-
Save m4scosta/97a5543561e25fc677c7 to your computer and use it in GitHub Desktop.
Ta dando Time Limit Exceeded
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <map> | |
#include <cstring> | |
#include <cstdlib> | |
using namespace std; | |
typedef pair<int, int> jogo; | |
map<int, map<int, int> > pontos; | |
map<int, map<int, int> > visitados; | |
int calc_points(const vector<jogo> & jogos, int n, int g) { | |
if (n < 0 || g < 0) | |
return 0; | |
if (visitados[n][g] && pontos[n][g] >= 0) { | |
return pontos[n][g]; | |
} | |
int max_pontos = 0; | |
for (int i = 0; i <= g; ++i) { | |
if (jogos[n].first + i < jogos[n].second) { | |
max_pontos = max(max_pontos, calc_points(jogos, n-1, g-i)); | |
} else if (jogos[n].first + i == jogos[n].second) { | |
max_pontos = max(max_pontos, 1 + calc_points(jogos, n-1, g-i)); | |
} else { | |
max_pontos = max(max_pontos, 3 + calc_points(jogos, n-1, g-i)); | |
break; | |
} | |
} | |
pontos[n][g] = max_pontos; | |
visitados[n][g] = 1; | |
return max_pontos; | |
} | |
int main() | |
{ | |
int n, g, s, r; | |
vector <jogo> jogos; | |
while (cin >> n >> g) { | |
jogos.clear(); | |
pontos.clear(); | |
visitados.clear(); | |
pontos = map<int, map<int, int> >(); | |
visitados = map<int, map<int, int> >(); | |
for (int i = 0; i < n; ++i) { | |
cin >> s >> r; | |
jogos.push_back(make_pair(s, r)); | |
} | |
calc_points(jogos, n, g); | |
cout << pontos[n-1][g] << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment