a53

Lee2

a53
Feb 5th, 2020
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define NMAX 1501
  3. using namespace std;
  4.  
  5. struct nod
  6. {
  7. int x,y,c;
  8. bool operator <(nod x)const
  9. {
  10. return c>x.c;
  11. }
  12. };nod xx;
  13. priority_queue <nod, vector < nod > > q;
  14.  
  15. int n, X, Y, Z, T, a[NMAX][NMAX], co[NMAX][NMAX];
  16. int mi1, mi2, mi3;
  17. int main()
  18. {
  19. int i, j;
  20. cin>>n>>X>>Y>>Z>>T;
  21. for(i=1; i<=n; i++)
  22. cin>>a[1][i];
  23. for(i=2; i<=n; i++)
  24. for(j=1; j<=n; j++)
  25. a[i][j]=1+(a[i-1][j-1]*X+a[i-1][j]*Y+a[i-1][j+1]*Z)%T;
  26. q.push({1,1,a[1][1]});
  27. while(!q.empty() and co[n][n]==0)
  28. {
  29. xx=q.top();
  30. if(xx.x>1 and co[xx.x-1][xx.y]==0){q.push({xx.x-1,xx.y,xx.c+a[xx.x-1][xx.y]});co[xx.x-1][xx.y]=xx.c+a[xx.x-1][xx.y];}
  31. if(xx.x<n and co[xx.x+1][xx.y]==0){q.push({xx.x+1,xx.y,xx.c+a[xx.x+1][xx.y]});co[xx.x+1][xx.y]=xx.c+a[xx.x+1][xx.y];}
  32. if(xx.y>1 and co[xx.x][xx.y-1]==0){q.push({xx.x,xx.y-1,xx.c+a[xx.x][xx.y-1]});co[xx.x][xx.y-1]=xx.c+a[xx.x][xx.y-1];}
  33. if(xx.y<n and co[xx.x][xx.y+1]==0){q.push({xx.x,xx.y+1,xx.c+a[xx.x][xx.y+1]});co[xx.x][xx.y+1]=xx.c+a[xx.x][xx.y+1];}
  34. q.pop();
  35. }
  36. int val=co[n][n];
  37. cout<<val;
  38. return 0;
  39. }
Add Comment
Please, Sign In to add comment