Advertisement
Guest User

Untitled

a guest
Dec 4th, 2014
907
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3.  
  4. using namespace std;
  5.  
  6. int R, C, D;
  7.  
  8. bool av[305][305];
  9. int ans[305][305][305][2] = { };
  10.  
  11. int main()
  12. {
  13.     cin >> R >> C >> D;
  14.    
  15.     for(int i = 1; i <= R; ++i)
  16.     {
  17.         for(int j = 1; j <= C; ++j)
  18.         {
  19.             cin >> av[i][j];
  20.         }
  21.     }
  22.  
  23.     for(int d = 0; d <= D; d++)
  24.     {
  25.         ans[R][C][d][0] = ans[R][C][d][1] = 1;
  26.     }
  27.  
  28.     for(int r = R; r > 0; r--)
  29.     {
  30.         for(int c = C; c > 0; c--)
  31.         {
  32.             if(r == R && c == C) continue;
  33.             if(av[r][c])
  34.             {
  35.                 ans[r][c][D][0] = ans[r + 1][c][1][1];
  36.                 ans[r][c][D][1] = ans[r][c + 1][1][0];
  37.                 for(int d = 0; d < D; d++)
  38.                 {
  39.                     ans[r][c][d][0] = (ans[r][c + 1][d + 1][0] + ans[r + 1][c][1][1]) % 20011;
  40.                     ans[r][c][d][1] = (ans[r][c + 1][1][0] + ans[r + 1][c][d + 1][1]) % 20011;
  41.                 }
  42.             }
  43.         }
  44.     }
  45.  
  46.     cout << ans[1][1][0][0];
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement