提交时间:2024-04-06 14:49:54
运行 ID: 141918
# 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 && n1 < 1 ) ) { return 0 ; } if ( bg ( s - w [n1] , n1 - 1 ) ) { cout << w [n1] << endl ; return 1 ; } return bg ( s , 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 ; }