提交时间:2024-04-06 14:59:38

运行 ID: 141935

# include <bits/stdc++.h> using namespace std ; int w [33] , s , n ; int bg ( int s1 , int n1 ) { if ( s1 == 0 ) { return 1 ; } if ( s1 < 0 || ( s1 > 0 && n1 < 1 ) ) { return 0 ; } if ( bg ( s1 - w [n1] , n1 - 1 ) ) { cout << w [n1] << endl ; return 1 ; } return bg ( s1 , n1 - 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 ; }