來源:牛客網
題目描述
輸入描述:
輸出描述:
每組數據輸出一行,包含一個整數表示非空子集的
meet in the middle
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
using namespace std;
//actually a=3,b=4,5 ; x=2,y=3 ÐèÒª¸ß¾«¶È
//10000*10000*35
//±ä³É17¸ö¾Í²»ÓÃÁË *17
map<long,long long> f;
long p[35],q[35],n,m,x,y;
long long sum;
void dfs(long step,long a,long b)
{
if (step==m)
f[a*y-b*x]++;
else
{
dfs(step+1,a,b);
dfs(step+1,a+p[step],b+q[step]);
}
}
void DFS(long step,long a,long b)
{
if (step==n)
sum+=f[-a*y+b*x];
else
{
DFS(step+1,a,b);
DFS(step+1,a+p[step],b+q[step]);
}
}
int main()
{
map<long,long long>::iterator j;
long t,i;
long long total;
scanf("%ld",&t);
while (t--)
{
scanf("%ld%ld%ld",&n,&x,&y);
for (i=0;i<n;i++)
scanf("%ld%ld",&p[i],&q[i]);
m=n>>1;
f.clear();
sum=0;
dfs(0,0,0);
DFS(m,0,0);
printf("%lld\n",sum-1);
}
return 0;
}