nullzero

sumn

Oct 12th, 2012
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. #include <cstdio>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. vector<int> vec;
  7.  
  8. void print(){
  9.     for(int i = 0; i < (int)vec.size(); ++i) printf("%d ", vec[i]);
  10.     printf("\n");
  11. }
  12.  
  13. void calc(int remain, int base){
  14.     if(remain == 0){
  15.         print();
  16.         return;
  17.     }
  18.     for(int i = base; i <= remain; ++i){
  19.         vec.push_back(i);
  20.         calc(remain - i, i);
  21.         vec.pop_back();
  22.     }
  23. }
  24.  
  25. int main(){
  26.     int n;
  27.     scanf("%d", &n);
  28.     calc(n, 1);
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment