vector<int> result; int money[4]={1,2,5,10}; void dfs(int total,int index){ if(total==0){ for(int i=0;i<result.size();++i){ cout<<result[i]<<" "; } cout<<endl; return ; } else if(total<0) return ; else{ for(int i=index;i<4;++i){ result.push_back(money[i]); dfs(total-money[i],i); result.pop_back(); } } }
时间: 2024-12-28 00:09:16