【codeforces 111C】 Petya and Spiders
来源:互联网 发布:表格删除重复数据 编辑:程序博客网 时间:2024/05/19 19:43
H - Petya and Spiders
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Submit
Status
Description
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 Input
Input
1 1
Output
0
Input
2 3
Output
4
Hint
In the first sample the only possible answer is:
s
In the second sample one of the possible solutions is:
rdl
rul
s denotes command “stay idle”, l, r, d, u denote commands “crawl left”, “crawl right”, “crawl down”, “crawl up”, correspondingly.
#include<iostream>#include<stdio.h>#include<string.h>using namespace std;int n,m;int ans;int full;int dp[45][(1<<6)][(1<<6)];int get[(1<<6)];bool check(int a,int b,int c) // sta is legal is(↑,↓,←,→,中的合法情况){ int sta=a|b|c|(b<<1)|(b>>1); return ((sta&(full))==(full));}void work(){ for(int i=0;i<n;i++) for(int j=0;j<=full;j++) for(int k=0;k<=full;k++) for(int l=0;l<=full;l++) if(check(j,k,l)) dp[i+1][k][l]=max(dp[i+1][k][l],dp[i][j][k]+get[k]); for(int i=0;i<=full;i++) ans=max(ans,dp[n][i][0]);}int main(){ scanf("%d%d",&n,&m); if(n<m) swap(n,m); //maintain the chracter n<=6 full=(1<<m)-1; for(int i=0;i<n+1;i++) for(int j=0;j<=full;j++) for(int k=0;k<=full;k++) dp[i][j][k]=-99999; for(int i=0;i<=full;i++) dp[0][0][i]=0,get[i]=m-__builtin_popcount(i); work(); printf("%d",ans);}
- codeforces 111C Petya and Spiders
- 【codeforces 111C】 Petya and Spiders
- CodeForces - 111C Petya and Spiders
- codeforces 111C Petya and Spiders 状态压缩
- Codeforces 111C Petya and Spiders 题解&代码
- Codeforces Beta Round #85 (Div. 1 Only), problem: (C) Petya and Spiders 状态压缩
- Codeforces Beta Round #85 (Div. 1 Only) C. Petya and Spiders
- 状态压缩DP poj—1185 炮兵阵地 和 cf 111 Problem C Petya and Spiders (经典)
- cf 85 E. Petya and Spiders
- CodeForces 890C Petya and Catacombs
- CodeForces 111B - Petya and Divisors
- CodeForces 111B Petya and Divisors
- Petya and Staircases CodeForces
- [Codeforces 66C] Petya and File System (模拟)
- Codeforces 66C Petya and File System(STL--map)
- Codeforces Round #445 C. Petya and Catacombs 贪心
- Codeforces 890 C. Petya and Catacombs (贪心)
- 【CodeForces】A. Petya and Strings
- 关于SYP'BLOG,关于Problem&Solutions
- 第二天,tranform ,图片浏览器,帧动画代码(我很勤劳的0.0)
- JS之浏览器对象
- Java中的BIO、NIO、AIO(NIO2)
- elasticsearch评分进阶
- 【codeforces 111C】 Petya and Spiders
- 【bzoj1560】【jsoi2009】【火星藏宝图】【dp】
- android中的回调
- lightoj 1374 Confusion in the Problemset
- leetcode笔记:Find Median from Data Stream
- Leetcode236: Interleaving String
- iOS程序员从小白到大神必读资料汇总(一)
- 详细整理:UITableView优化技巧
- Linux read / write详解