因为最多24个数...可以用2^24表示所有的存在情况...然后DP更新就是..有些卡时间..
Program:
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<set>
#include<algorithm>
#include<cmath>
#define oo 1000000007
#define ll long long
#define pi acos(-1.0)
#define MAXN 505
using namespace std;
int n,m,a[26],b[3];
ll dp[17000000],t;
int main()
{
int i,x,p,sum,need;
while (~scanf("%d",&n))
{
for (i=1;i<=n;i++) scanf("%d",&a[i]);
scanf("%d",&m);
for (i=1;i<=m;i++) scanf("%d",&b[i]);
dp[0]=1;
need=(1<<n)-1;
for (x=1;x<=need;x++)
{
p=x;
t=sum=i=0;
while (p)
{
if (p%2)
{
t+=dp[x&(~(1<<i))];
sum+=a[i+1];
}
i++,p>>=1;
}
for (i=1;i<=m;i++)
if (sum==b[i]) t=0;
dp[x]=t%oo;
}
printf("%I64d\n",dp[need]);
}
return 0;
}