标签:
Time limit : 2sec / Stack limit : 256MB / Memory limit : 256MB
Score : 300 points
Tak has N cards. On the i-th (1≤i≤N) card is written an integer xi. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection?
The input is given from Standard Input in the following format:
N A x1 x2 … xN
Print the number of ways to select cards such that the average of the written integers is exactly A.
4 8 7 9 8 9
5
分析:二维背包;
代码:
#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <algorithm> #include <climits> #include <cstring> #include <string> #include <set> #include <map> #include <queue> #include <stack> #include <vector> #include <list> #define rep(i,m,n) for(i=m;i<=n;i++) #define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++) #define mod 1000000000 #define inf 0x3f3f3f3f #define vi vector<int> #define pb push_back #define mp make_pair #define fi first #define se second #define ll long long #define pi acos(-1.0) #define pii pair<int,int> #define Lson L, mid, rt<<1 #define Rson mid+1, R, rt<<1|1 const int maxn=1e5+10; using namespace std; ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);} ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;} int n,m,k,t; ll dp[51][2501]; int a,now; ll ans; int main() { int i,j; dp[0][0]=1; scanf("%d%d",&n,&a); rep(i,1,n) { scanf("%d",&k); now+=k; for(j=i;j>=1;j--) for(t=now;t>=k;t--) dp[j][t]+=dp[j-1][t-k]; } rep(i,1,n)ans+=dp[i][a*i]; printf("%lld\n",ans); //system("Pause"); return 0; }
标签:
原文地址:http://www.cnblogs.com/dyzll/p/5816200.html