You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
707 B
C++
33 lines
707 B
C++
#include <cstdio>
|
|
#include <algorithm>
|
|
using namespace std;
|
|
double A[55], tmp;
|
|
int B[55], Q, N, ans;
|
|
bool vis[55];
|
|
void dfs(int d, int x, double p, int s)
|
|
{
|
|
if (d > 3) return;
|
|
if (int(p) == p && int(p) % 5 == 0)
|
|
ans = max(ans, s);
|
|
for (int i = 0; i < N; i++)
|
|
if (!vis[i])
|
|
{
|
|
vis[i] = true;
|
|
dfs(d + 1, i, p + A[i], s + B[i]);
|
|
vis[i] = false;
|
|
}
|
|
}
|
|
int main()
|
|
{
|
|
scanf("%d", &Q);
|
|
while (Q--)
|
|
{
|
|
ans = 0;
|
|
scanf("%d", &N);
|
|
for (int i = 0; i < N; i++)
|
|
scanf("%lf%d", A + i, B + i);
|
|
dfs(0, 0, 0, 0);
|
|
printf("%d\n", ans);
|
|
}
|
|
return 0;
|
|
} |