amcbn

ProdusCartezian2

Nov 9th, 2021
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. /* [A][M][C][B][N] / [K][R][I][P][6][8] */
  2. #include <bits/stdc++.h>
  3. #include <unordered_map>
  4. using namespace std;
  5. typedef long long ll;
  6. const char sp = ' ', nl = '\n';
  7. const int MOD = 9973;
  8. ifstream fin("produscartezian2.in");
  9. ofstream fout("produscartezian2.out");
  10. int n;
  11. vector<int> v, curr;
  12.  
  13. void back(int idx) {
  14.     if (idx == v.size()) {
  15.         for (int& e : curr)
  16.             fout << e << sp;
  17.         fout << nl;
  18.     }
  19.     else {
  20.         for (int i = 1; i <= v[idx]; ++i) {
  21.             curr[idx] = i;
  22.             back(idx + 1);
  23.         }
  24.     }
  25. }
  26.  
  27. int main() {
  28.     ios::sync_with_stdio(0);
  29.     cin.tie(0), cout.tie(0);
  30.     fin >> n;
  31.     v.resize(n);
  32.     curr.resize(n);
  33.     for (int i = 0; i < n; ++i)
  34.         fin >> v[i];
  35.     back(0);
  36. }
Advertisement
Add Comment
Please, Sign In to add comment