標籤:style http color os io for ar cti
C. Petya and Spiders
Little Petya loves training spiders. Petya has a board n × m in size. Each cell of the board initially has a spider sitting on it. After one second Petya chooses a certain action for each spider, and all of them humbly perform its commands. There are 5 possible commands: to stay idle or to move from current cell to some of the four side-neighboring cells (that is, one command for each of the four possible directions). Petya gives the commands so that no spider leaves the field. It is allowed for spiders to pass through each other when they crawl towards each other in opposite directions. All spiders crawl simultaneously and several spiders may end up in one cell. Petya wants to know the maximum possible number of spider-free cells after one second.
Input
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 40, n·m ≤ 40) — the board sizes.
Output
In the first line print the maximum number of cells without spiders.
Sample test(s)input
1 1
output
0
input
2 3
output
4
題意:開始得分時候每個格子都有蜘蛛,然後每一秒鐘蜘蛛可以向四個方向爬行,或者靜止不動。 問1秒後有多少格子時空的。
sl : 貌似很久以前就看過這個題目但是因為種種原因不會搞,看題解也不明白,今天徒手花了下,感覺能搞,但是最後還是wa了,實在是逗。
看了題解,果然是經典的狀壓啊。 dp[i][now][pre] 表示 第i行蜘蛛的狀態為now 上一行的狀態為 pre, 這時候可能會出現不合法的轉移。怎麼不合法呢
就是相鄰的兩行的蜘蛛加上當前的蜘蛛數目不等於全部蜘蛛的數目,然後轉移就好辦了。從上一行轉移過來,記錄下上一行出現了多少個蜘蛛就好了。
http://codeforces.com/contest/111/submission/7485571