Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <queue>
- #include <iostream>
- #include <bitset>
- using namespace std;
- ifstream fin("sudest.in");
- ifstream fin2("sudest.in");
- ofstream fout("sudest.out");
- int n;
- int mat[102][102], A[102][102];
- int v[200];
- bitset < 102 > viz[102];
- int cate;
- queue < pair < int, int > > q;
- bool Posibil(int i, int j)
- {
- return (i >= 0 && j >= 0 && i <= n && j <= n);
- }
- void Lee(int i, int j)
- {
- q.push(make_pair(i, j));
- viz[i][j] = 1;
- int c = 0;
- while(!q.empty() && c <= cate)
- {
- i = q.front().first;
- j = q.front().second;
- q.pop();
- cout << i << ' ' << j << ' ' << c << ' ' << v[c] << '\n';
- if(Posibil(i, j + v[c]))
- {
- q.push(make_pair(i, j + v[c]));
- cout << "p: " << i << ' ' << j + v[c] << '\n';
- if(!viz[i][j + v[c]])
- A[i][j + v[c]] += mat[i][j];
- else
- A[i][j + v[c]] = max(A[i][j + v[c]], mat[i][j] + mat[i][j + v[c]]);
- viz[i][j + v[c]] = 1;
- }
- if(Posibil(i + v[c], j))
- {
- q.push(make_pair(i + v[c], j));
- cout << "d: " << i + v[c] << ' ' << j << '\n';
- if(!viz[i + v[c]][j])
- A[i + v[c]][j] += mat[i][j];
- else
- A[i + v[c]][j] = max(A[i + v[c]][j], mat[i][j] + mat[i + v[c]][j]);
- viz[i + v[c]][j] = 1;
- }
- c++;
- }
- fout << A[n][n];
- }
- void Gard()
- {
- for(int i = 0; i <= n + 1; i++)
- mat[i][0] = mat[i][n + 1] = mat[0][i] = mat[n + 1][i] = -1;
- }
- int main()
- {
- fin >> n;
- fin2 >> n;
- for(int i = 1; i <= n; i++)
- for(int j = 1; j <= n; j++)
- fin >> mat[i][j], fin2 >> A[i][j];
- fin >> cate;
- for(int i = 0; i < cate; i++)
- fin >> v[i];
- Gard();
- Lee(1, 1);
- fin.close();
- fout.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement