Advertisement
PedalaVasile

se

Feb 17th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.95 KB | None | 0 0
  1. #include <fstream>
  2. #include <queue>
  3. #include <iostream>
  4. #include <bitset>
  5.  
  6. using namespace std;
  7.  
  8. ifstream fin("sudest.in");
  9. ifstream fin2("sudest.in");
  10. ofstream fout("sudest.out");
  11.  
  12. int n;
  13. int mat[102][102], A[102][102];
  14. int v[200];
  15. bitset < 102 > viz[102];
  16. int cate;
  17.  
  18.  
  19. queue < pair < int, int > > q;
  20.  
  21. bool Posibil(int i, int j)
  22. {
  23.     return (i >= 0 && j >= 0 && i <= n && j <= n);
  24. }
  25.  
  26. void Lee(int i, int j)
  27. {
  28.     q.push(make_pair(i, j));
  29.  
  30.     viz[i][j] = 1;
  31.  
  32.     int c = 0;
  33.  
  34.     while(!q.empty() && c <= cate)
  35.     {
  36.         i = q.front().first;
  37.         j = q.front().second;
  38.  
  39.         q.pop();
  40.  
  41.         cout << i << ' ' << j << ' ' << c << ' ' << v[c] << '\n';
  42.  
  43.         if(Posibil(i, j + v[c]))
  44.         {
  45.             q.push(make_pair(i, j + v[c]));
  46.  
  47.             cout << "p: " << i << ' ' << j + v[c] << '\n';
  48.  
  49.             if(!viz[i][j + v[c]])
  50.                 A[i][j + v[c]] += mat[i][j];
  51.             else
  52.                 A[i][j + v[c]] = max(A[i][j + v[c]], mat[i][j] + mat[i][j + v[c]]);
  53.  
  54.             viz[i][j + v[c]] = 1;
  55.         }
  56.  
  57.         if(Posibil(i + v[c], j))
  58.         {
  59.             q.push(make_pair(i + v[c], j));
  60.  
  61.  
  62.             cout << "d: " << i + v[c] << ' ' << j << '\n';
  63.             if(!viz[i + v[c]][j])
  64.                 A[i + v[c]][j] += mat[i][j];
  65.             else
  66.                 A[i + v[c]][j] = max(A[i + v[c]][j], mat[i][j] + mat[i + v[c]][j]);
  67.  
  68.             viz[i + v[c]][j] = 1;
  69.         }
  70.  
  71.         c++;
  72.     }
  73.  
  74.     fout << A[n][n];
  75. }
  76.  
  77. void Gard()
  78. {
  79.     for(int i = 0; i <= n + 1; i++)
  80.         mat[i][0] = mat[i][n + 1] = mat[0][i] = mat[n + 1][i] = -1;
  81. }
  82.  
  83. int main()
  84. {
  85.     fin >> n;
  86.     fin2 >> n;
  87.  
  88.     for(int i = 1; i <= n; i++)
  89.         for(int j = 1; j <= n; j++)
  90.             fin >> mat[i][j], fin2 >> A[i][j];
  91.  
  92.  
  93.     fin >> cate;
  94.  
  95.  
  96.  
  97.     for(int i = 0; i < cate; i++)
  98.         fin >> v[i];
  99.  
  100.     Gard();
  101.  
  102.     Lee(1, 1);
  103.  
  104.     fin.close();
  105.     fout.close();
  106.     return 0;
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement