提交时间:2023-12-02 11:14:56
运行 ID: 113604
# include <bits/stdc++.h> using namespace std ; int a [114514] ; int m , n , cnt = 0 ; void dfs ( int cur , int s1 , int s2 ) { if ( cur >= m && abs ( s1 - s2 ) == n ) { cnt ++ ; return ; } else if ( cur <= m ) { dfs ( cur + 1 , s1 + a [cur] , s2 ) ; dfs ( cur + 1 , s1 , s2 + a [cur] ) ; } else { return ; } } int main ( ) { cin >> m >> n ; for ( int i = 1 ; i <= m ; i ++ ) { cin >> a [i] ; } sort ( a + 1 , a + m + 1 ) ; dfs ( 1 , 0 , 0 ) ; cout << cnt / 2 << endl ; return 0 ; }