提交时间:2023-12-02 10:17:27
运行 ID: 113406
#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]; } if((s - t) % 2 == 1){ cout << 0; return 0; } m = (s - t) / 2; if(s < t) cout << 0; else cout << f(); return 0; }