#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define BET(a,b,c) ((a)<=(b)&&(b)<(c)) #define FOR(i,n) for(int i=0,i##_end=(int(n));i VI; typedef vector VVI; int L[222][222]; struct data{ int row, col; int vitality; bool visitedOasis; }; bool visited[202][202][1002][2]; int dx[] = {0,1,0,-1}; int dy[] = {1,0,-1,0}; int main() { int N,V,ox,oy; cin>>N>>V>>ox>>oy; ox--; oy--; FOR(i,N) FOR(j,N) scanf("%d", &L[i][j]); queue qu; qu.push((data){ 0, 0, V, false}); memset(visited , 0 , sizeof(visited)); while(!qu.empty()){ data now = qu.front(); qu.pop(); if(now.row == oy && now.col == ox && !now.visitedOasis){ qu.push((data){now.row,now.col,2*now.vitality,true}); } if(visited[now.row][now.col][now.vitality][now.visitedOasis]++) continue; if(now.row == N - 1 && now.col == N - 1){ puts("YES"); return 0; } FOR(i,4){ int nr = now.row + dy[i]; int nc = now.col + dx[i]; if(BET(0,nr,N) && BET(0,nc,N)){ int nv = now.vitality; nv -= L[nr][nc]; if(nv > 0){ qu.push((data){nr, nc, nv, now.visitedOasis}); } } } } puts("NO"); return 0; }