样例输出
三维dp
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#include <queue>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
ll dp[55][55][2550];
ll x[50];
int main()
{
int n,a;
scanf("%d%d",&n,&a);
memset(dp,0,sizeof(dp));
dp[0][0][0]=1;
for (int i=0;i<n;i++)
scanf("%lld",&x[i]);
for (int i=1;i<=n;i++)
{
for (int j=0;j<=i;j++)
{
for (int k=0;k<=2510;k++)
{
if (k>=x[i-1] && j>=1)
dp[i][j][k]+=dp[i-1][j-1][k-x[i-1]]+dp[i-1][j][k];
else
dp[i][j][k]+=dp[i-1][j][k];
}
}
}
ll ans=0;
for (int i=1;i<=n;i++)
ans+=dp[n][i][i*a];
printf("%lld\n",ans);
return 0;
}
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#include <queue>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
ll gcd(ll a,ll b){
return b?gcd(b,a%b):a;
}
bool cmp(int x,int y)
{
return x>y;
}
const int N=2e5+20;
const ll mod=1e9+7;
ll dp[105][10005];
int main()
{
int n,a;
int x;
ll ans=0;
ll now=0;
dp[0][0]=1;
scanf("%d%d",&n,&a);
for(int i=1;i<=n;i++)
{
scanf("%d",&x);
now+=x;
for(int j=i;j>=1;j--)
{
for(int k=now;k>=x;k--)
{
dp[j][k]+=dp[j-1][k-x];
}
}
}
for(int i=1;i<=n;i++)
{
ans+=dp[i][a*i];
}
printf("%lld\n",ans);
return 0;
}