Codeforces Beta Round #85 (Div. 1 Only) C (狀態壓縮或是數學?)

來源:互聯網
上載者:User

標籤: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 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.