Advertisement
ROMaurice

Untitled

Feb 22nd, 2015
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. /* Matraguna Mihai */
  2. #include <iostream>
  3. #include <fstream>
  4.  
  5. using namespace std;
  6.  
  7. ifstream fin("homm.in");
  8. ofstream fout("homm.out");
  9.  
  10. const int NMax = 100;
  11. const int MMax = 100;
  12. const int KMax = 20;
  13.  
  14. int N, M, K, x, y, x_f, y_f;
  15.  
  16. int Map[NMax][MMax]; // 0.009 MB
  17. int DP[KMax][NMax][MMax]; // 0.19 MB, bitch!
  18.  
  19. int di[4] = {-1, 1, 0, 0};
  20. int dj[4] = {0, 0, 1, -1};
  21.  
  22. void Read()
  23. {
  24. fin >> N >> M >> K;
  25.  
  26. for(int i = 1; i <= N; i++)
  27. for(int j = 1; j <= M; j++)
  28. fin >> Map[i][j];
  29.  
  30. fin >> x >> y >> x_f >> y_f;
  31.  
  32. for(int _k = 0; _k <= K; _k++)
  33. DP[x][y][_k] = 1; // 0 + 0 = 0
  34.  
  35. for(int i = 1; i <= N; i++)
  36. for(int j = 1; j <= M; j++)
  37. for(int _k = 1; _k <= K; _k++)
  38. for(int d = 0; d < 4; d++)
  39. {
  40. if(!Map[i][j])
  41. DP[i][j][_k] += DP [i + di[d]] [j + dj[d]] [_k - 1];
  42. }
  43.  
  44.  
  45. int Result = 0;
  46. for(int _k = 0; _k <= K; _k++)
  47. Result += DP[x_f][y_f][_k];
  48. fout << Result << "\n";
  49.  
  50. //cout << Result;
  51. }
  52.  
  53. int main()
  54. {
  55. Read();
  56. return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement