提交时间:2023-12-02 10:13:52

运行 ID: 113398

#include<iostream> using namespace std; const int N = 30; int n, t, w[N], s = 0, m; int f(int x = 1, int u = 0){ if(x > n){ // cout << u << endl; if(u == m) return 1; return 0; } int res = 0; u += w[x]; res += f(x + 1, u); u -= w[x]; res += f(x + 1, u); return res; } int main(){ cin >> n >> t; for(int i = 1; i <= n; i++){ cin >> w[i]; s += w[i]; } m = (s - t) / 2; if(s < t) cout << 0; else cout << f(); return 0; }