#include <iostream>
using namespace std;
int _sum;
int n;
int list[ 4 ] = { 1 , 2 , 5 , 10 };
void dfs( int ans[] , int depth , int length , int cur_sum ){
if( depth == 4 ) {
int i;
if( length == 0 ) {
cout << "空集" << endl;
return;
}
for( i = 0 ; i < length ; i ++ ) {
cout << ans[ i ] << " ";
}
cout << endl;
}
if( depth < 4 ) {
//继续或者开始选第depth个硬币
ans[ length ] = list[ depth ];
dfs( ans , depth + 1 , length + 1 , cur_sum + list[ depth ] );
//不再或者不选第depth个硬币
dfs( ans , depth + 1 , length , cur_sum );
}
}
int main() {
//输入n
int ans[ 100 ] = { 0 };
dfs( ans , 0 , 0 , 0 );
}
求子集
最新推荐文章于 2022-03-12 00:33:41 发布