链接:
https://www.nowcoder.com/acm/contest/94/K
来源:牛客网
来源:牛客网
题目描述
小马哥有
杯盐水,第
杯有
单位的盐和
单位的水。小马哥很无聊,于是他想知道有多少种这
杯盐水的非空子集,倒在一起之后盐和水的比是






输入描述:
输入第一行包含一个整数
,代表数据组数。

每组数据第一行包含三个整数
表示
和
的最大公约数。




接下来
行,第
行包含两个整数



输出描述:
每组数据输出一行,包含一个整数表示非空子集的
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;
}