码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces Beta Round #85 (Div. 1 Only) C (状态压缩或是数学?)

时间:2014-08-17 01:04:31      阅读:245      评论:0      收藏:0      [点我收藏+]

标签: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 

 

Codeforces Beta Round #85 (Div. 1 Only) C (状态压缩或是数学?),布布扣,bubuko.com

Codeforces Beta Round #85 (Div. 1 Only) C (状态压缩或是数学?)

标签:style   http   color   os   io   for   ar   cti   

原文地址:http://www.cnblogs.com/acvc/p/3917145.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!