Link: 2018 South-South University Program Design competition: K-Pony Super Brine
Test instructions: Small Mago Cup brine, Cup has unit of Salt and unit of water. Pony is very bored, so he wants to know how many kinds of this cup of brine non-empty set, pour together after the salt and water ratio is.
Troubleshooting: Binary. MAXN = 35, Direct enumeration is sure to be tle, binary time complexity is enough.
(A1 + A2)/(B1 + B2) = x/y; A1 * Y-B1 * x = B2 * x-a2 * y;
because there are 0 of the existence, the result is to reduce one.
#include <bits/stdc++.h>
using namespace std;
const int MAXN = + Ten;
int n, x, y;
int A[MAXN], B[MAXN];
A long long ans = 0;
Map<long long, int> MP;
void DFS (int l, int r, int A, int B, int flag)
{
if (L = = r) {
if (flag) ans + = mp[x * b-y * A];
else Mp[y * a-x * b]++;
return;
}
DFS (l + 1, R, A, B, flag);
DFS (l + 1, R, A + a[l], B + b[l], flag);
}
int main ()
{
int T;
scanf ("%d", &t);
while (t--) {
mp.clear ();
Ans = 0;
scanf ("%d%d%d", &n, &x, &y);
for (int i = 0; i < n; i++) scanf ("%d%d", &a[i], &b[i]);
DFS (0, N/2, 0, 0, 0);
DFS (N/2, N, 0, 0, 1);
printf ("%lld\n", ans-1);
}
return 0;
}