CodeForces - 111C Petya and Spiders
来源:互联网 发布:数据自动统计软件 编辑:程序博客网 时间:2024/06/02 03:26
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 andm (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
In the first sample the only possible answer is:
s
In the second sample one of the possible solutions is:
rdlrul
s denotes command "stay idle", l, r, d, u denote commands "crawl left", "crawl right", "crawl down", "crawl up", correspondingly
题意:给你一个N*M的格子
每个格子上有一个蜘蛛
每个蜘蛛可以进行5个动作
1 不动 2 向左 3 向右 4 向上 5 向下
n*m的矩形 == m*n的矩形 减小状态数目
逆向思维 放入k个蜘蛛 把所有点占据满
蜘蛛最多能影响上一行的状态
用二进制模拟
ACcode:
#include<bits/stdc++.h>using namespace std;const int maxn = 1<< 7;int dp[50][maxn][maxn],res[maxn],n,m,mask;bool check(int a,int b,int c) //保证当前的格子被占满 当前的格子会作为下一行的上一个状态{ int x=b|(b<<1)|(b>>1)|a|c; if( (x&mask) == mask) return 1; return 0;}int num(int x) //记录蜘蛛个数{ int cnt = 0; while(x>0){ x-=(x&(-x)); cnt++; } return m-cnt;}int main(){ int ans=0; scanf("%d%d",&n,&m); if(n<m) swap(n,m); //优化进制 mask=(1<<m)-1; memset(dp,0,sizeof dp); for(int i=0;i<=mask;i++) res[i]=num(i); for(int k=0;k<=mask;k++){//预处理第一行 for(int l=0;l<=mask;l++){ if(check(0,k,l) == 1) dp[1][k][l]=max(dp[1][k][l],dp[0][0][k]+res[k]); } } for(int i=1;i<n;i++){ for(int j=0;j<=mask;j++){ for(int k=0;k<=mask;k++){ if(dp[i][j][k] != 0 ){ for(int l=0;l<=mask;l++){ if(check(j,k,l) == 1) dp[i+1][k][l]=max(dp[i+1][k][l],dp[i][j][k]+res[k]); } } } } } for(int j=0;j<=mask;j++) ans=max(ans,dp[n][j][0]); printf("%d\n",ans); return 0;}
- 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
- 1、计算5位学员平均分(0110)
- JS
- 移动端项目总结
- 无缝滚图的制作
- CUDA总结:CUBLAS
- CodeForces - 111C Petya and Spiders
- 2、猜数游戏
- spark 报错收集
- 欢迎使用CSDN-markdown编辑器
- 3、购物金额结算
- OpenCV、Skimage、PIL图像处理的细节差异
- 果编译时候出现错误:QMAKESPEC has not been set, so configuration cannot be deduced.
- 怎么解决java.lang.NoClassDefFoundError错误
- 4、求数组最大值