首页 > 代码库 > Codeforces Beta Round #85 (Div. 1 Only) C (状态压缩或是数学?)
Codeforces Beta Round #85 (Div. 1 Only) C (状态压缩或是数学?)
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.
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 40, n·m ≤ 40) — the board sizes.
In the first line print the maximum number of cells without spiders.
1 1
0
2 3
4
题意:开始得分时候每个格子都有蜘蛛,然后每一秒钟蜘蛛可以向四个方向爬行,或者静止不动。 问1秒后有多少格子时空的。
sl : 貌似很久以前就看过这个题目但是因为种种原因不会搞,看题解也不明白,今天徒手花了下,感觉能搞,但是最后还是wa了,实在是逗。
看了题解,果然是经典的状压啊。 dp[i][now][pre] 表示 第i行蜘蛛的状态为now 上一行的状态为 pre, 这时候可能会出现不合法的转移。怎么不合法呢
就是相邻的两行的蜘蛛加上当前的蜘蛛数目不等于全部蜘蛛的数目,然后转移就好办了。从上一行转移过来,记录下上一行出现了多少个蜘蛛就好了。
http://codeforces.com/contest/111/submission/7485571