提交时间:2024-04-06 14:41:42

运行 ID: 141911

# include <bits/stdc++.h> using namespace std ; int w [33] , s , n ; int bg ( int s , int n ) { if ( s == 0 ) { return 1 ; } if ( s < 0 || ( s > 0 && n < 1 ) ) { return 0 ; } if ( bg ( s - w ( n ) , n - 1 ) ) { cout << w [n] << endl ; } return bg ( s , n - 1 ) ; } int main ( ) { cin >> s >> n ; for ( int i = 1 ; i <= n ; i ++ ) { cin >> w [i] ; } if ( ! bg ( s , n ) ) { cout << "Failed!" << endl ; } return 0 ; }