Farmer John has recently built an enormous barn consisting of anN×NN×Ngrid of rooms , numbered from(1,1)(1,1)up to(N,N)(N,N). Being somewhat afraid of the dark, Bessie the cow wants to turn on the lights in as many rooms as possible. Bessie starts in room(1,1)(1,1), the only room that is initially lit. In some rooms, she will find light switches that she can use to toggle the lights in other rooms; for example there might be a switch in room(1,1)(1,1)that toggles the lights in room(1,2)(1,2). Bessie can only travel through lit rooms, and she can only move from a room(x,y)(x,y)to its four adjacent neighbors,,and. Please determine the maximum number of rooms Bessie can illuminate.
Farmer John has recently built an enormous barn consisting of an N×NN×N grid of rooms (2≤N≤1002≤N≤100), numbered from (1,1)(1,1) up to (N,N)(N,N). Being somewhat afraid of the dark, Bessie the cow wants to turn on the lights in as many rooms as possible. Bessie starts in room (1,1)(1,1), the only room that is initially lit. In some rooms, she will find light switches that she can use to toggle the lights in other rooms; for example there might be a switch in room (1,1)(1,1) that toggles the lights in room (1,2)(1,2). Bessie can only travel through lit rooms, and she can only move from a room (x,y)(x,y) to its four adjacent neighbors (x−1,y)(x−1,y), (x+1,y)(x+1,y), (x,y−1)(x,y−1)and (x,y+1)(x,y+1) (or possibly fewer neighbors if this room is on the boundary of the grid). Please determine the maximum number of rooms Bessie can illuminate.
标签: HBC24043简单的公式[USACO 2015 Dec S]Switching on the Lights题解