Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include <cmath>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. int a[3][3], c = 2, ans, b[3][3];
  7.  
  8. int op()
  9. {
  10.   return a[0][0] * a[1][1] * a[2][2] + a[0][2] * a[1][0] * a[2][1] +
  11.          a[0][1] * a[1][2] * a[2][0] - a[0][2] * a[1][1] * a[2][0] -
  12.          a[0][1] * a[1][0] * a[2][2] - a[0][0] * a[1][2] * a[2][1];
  13. }
  14.  
  15. void rec(int i, int j)
  16. {
  17.   if (j == 3)
  18.   {
  19.     j = 0;
  20.     ++i;
  21.   }
  22.   if (i == 3)
  23.   {
  24.     int cur = op();
  25.     if (cur > ans)
  26.     {
  27.       ans = cur;
  28.       for(i = 0; i < 3; ++i)
  29.         for(j = 0; j < 3; ++j)
  30.           b[i][j] = a[i][j];
  31.     }
  32.     return;
  33.   }
  34.   a[i][j] = 1;
  35.   rec(i, j+1);
  36.   a[i][j] = -1;
  37.   rec(i, j+1);
  38.   if (c > 0)
  39.   {
  40.     --c;
  41.     a[i][j] = 4;
  42.     rec(i, j+1);
  43.     ++c;
  44.   }
  45. }
  46.  
  47. int main()
  48. {
  49.   rec(0, 0);
  50.   cout << ans << endl;
  51.   for(int i = 0; i < 3; ++i)
  52.   {
  53.     for(int j = 0; j < 3; ++j)
  54.        cout << b[i][j] << " ";
  55.     cout << endl;
  56.   }
  57.   return 0;  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement