Пожалуйста, подпишитесь на официальный канал Codeforces в Telegram по ссылке https://t.me/codeforces_official. ×

Блог пользователя F.a.F

Автор F.a.F, история, 7 лет назад, По-английски

The problem statement is "Given a board of N(1<=N=3) rows and M(1<=M<=50) columns, place the minimum number of knights such that every cell either contains a knight or is attacked by at least one knights." 1<=T<=150 test cases

Link :- https://www.codechef.com/problems/KNICOV

I am having a hard time figuring out the states of the DP and transitions between them. Can someone please explain in detail how to go about solving this?

  • Проголосовать: нравится
  • -3
  • Проголосовать: не нравится

»
7 лет назад, # |
Rev. 3   Проголосовать: нравится +10 Проголосовать: не нравится

This can solve by BIT-DP. (DP with bitmasks)



So, you should memory only 3*4=12 cells's situation in maximum.
You can solve with dp[i][j].

  • i: Current column which is putting knights.
  • j: The situation of cell (the knight was put or not) in last 2 columns, current column and next 1 column. It can be represent in bitmasks and the number of situation is 4096 (2^12) in maximum.
The complexity is O( 2M * 4 * N ).
Sorry for my poor English.