The meaning of problems
https://vjudge.net/problem/AtCoder-2037
Some selected such that the number and the average value is equal to a, the number of programs to ask.
Thinking
Set DP [i] [j] is the number of programs selected from i and j, the number, if the currently selected x, then dp [j + 1] [w + x] + = dp [j] [w].
Order dp [0] [0] = 1, j Note that reverse traversal
Code
#include<bits/stdc++.h> using namespace std; #define inf 0x3f3f3f3f #define ll long long const int N=55; const int mod=1e9+7; const double eps=1e-8; const double PI = acos(-1.0); #define lowbit(x) (x&(-x)) ll dp[N][N*N]; int main() { std::ios::sync_with_stdio(false); int n,a; cin>>n>>a; dp[0][0]=1; for(int i=1;i<=n;i++) { int x; cin>>x; for(int j=i-1;j>=0;j--) for(int w=0;w<=N*j;w++) { dp[j+1][w+x]+=dp[j][w]; // cout<<j+1<<" "<<w+x<<" "<<dp[j+1][w+x]<<endl; } } ll ans=0; for(int i=1;i<=n;i++) { ans+=dp[i][i*a]; } cout<<ans<<endl; return 0; }