1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> #include <queue> #include <set> #include <vector> using namespace std;
const int INF = ~0u>>1; typedef pair <int,int> P; #define MID(x,y) ((x+y)>>1) #define iabs(x) ((x)>0?(x):-(x)) #define REP(i,a,b) for(int i=(a);i<(b);i++) #define FOR(i,a,b) for(int i=(a);i<=(b);i++) #define pb push_back #define mp make_pair #define print() cout<<"--------"<<endl
#define maxn 1010 int dp[maxn],a[maxn]; int main(){ int T,t = 0; int n,d,sum; cin >> T; while (t ++ < T){ scanf("%d%d", &n, &d); sum = 0; for (int i = 1; i <= n; i ++){ scanf("%d", &a[i]); sum += a[i]; } sort(a + 1,a + n + 1); memset(dp,0,sizeof(dp)); dp[0] = 1; int ans = 0; for (int i = n; i > 0; i --){ sum -= a[i]; for (int v = max(d - sum - a[i] + 1, 0); v <= d - sum; v++) ans += dp[v]; for (int v = d; v >= a[i]; v --) dp[v] += dp[v - a[i]]; } printf("%d %dn",t,a[1] > d ? 0 : ans); } return 0; }
|