Advertisement
MeShootIn

ЗАДАЧА D

Oct 22nd, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include <cstdio>
  2. #include <cmath>
  3. #include <iostream>
  4. #include <vector>
  5. #include <queue>
  6. #include <algorithm>
  7. #include <climits>
  8. using namespace std;
  9. vector <int> tmp(80);
  10. int res;
  11. void rec(int n, int k, int pos)
  12. {
  13.      if(n < 0) return;
  14.      if(!n)
  15.      {
  16.            int i;
  17.            for(i = pos - 1; i > 0; i--) if(tmp[i - 1] - tmp[i] < 2) return;
  18.            printf("%d=", res);
  19.            for(i = pos - 1; i > 0; i--) printf("%d+", tmp[i]);
  20.            printf("%d\n", tmp[0]);
  21.      }
  22.      else
  23.      {
  24.          if(n - k >= 0)
  25.          {
  26.               tmp[pos] = k;
  27.               rec(n - k, k, pos + 1);
  28.          }
  29.          if(k - 1 > 0) rec(n, k - 1, pos);
  30.      }
  31. }
  32. int main()
  33. {
  34.     scanf("%d", &res);
  35.     rec(res, res, 0);
  36.     //system("PAUSE");
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement