codeforces 111C/112E Petya and Spiders
题目: Petya and Spiders
传送门:
http://codeforces.com/problemset/problem/111/C
http://codeforces.com/problemset/problem/112/E
分析:
(1)由n·m<=40可以想到状态压缩动态规划,方程很好想,用四进制表示状态,用位运算优化。
(2)由n·m<=40可以想到分类构造公式。
代码:
1)
#include<cstdio>
#include<algorithm>
#define inf 2147483647
int n,m,statenum;
int num[],f[][];
bool pd(int state1,int state2){
int a1=state1%,b1=,c1=,a2=state2%,b2=,c2=;
state1/=;state2/=;
for(int i();i<=*n;i+=){
c1=b1;b1=a1;a1=state1%;state1/=;
c2=b2;b2=a2;a2=state2%;state2/=;
if(b2== && b1!=)return false;
if(b1== && b2!=)return false;
if(b1== && a1!= && c1!=)return false;
}
return true;
}
void solve(){
statenum=(<<n*)-;
for(int i();i<=statenum;++i)
{f[][i]=inf;for(int j=i;j;j>>=)num[i]+=(j&)==;}
f[][statenum]=;
int x=,y=;
for(int k();k<=m+;++k,x=!x,y=!y)
for(int i();i<=statenum;++i){
f[y][i]=inf;
for(int j();j<=statenum;++j)
if(f[x][j]!=inf && pd(i,j))
f[y][i]=std::min(f[y][i],f[x][j]+num[i]);
}
if(f[y][]==inf)
printf("");else printf("%d",n*m-f[x][]);
}
int main(){
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
scanf("%d %d",&n,&m);
if(n>m)std::swap(n,m);
solve();
//fclose(stdin);fclose(stdout);
return ;
}
2)
#include<cstdio>
#define P(x) return printf("%d\n",m*n-(x)),0;
int main(){
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int n,m;
scanf("%d%d",&n,&m);
if(n>m)n^=m,m^=n,n^=m;
switch(n){
case :P((m+)/)
case :P((m+)/)
case :P(m/*+(m%=)+(m==))
case :P(m+(m==||m==||m==))
case :P(m/*-(m==)+(m%=)++(m>))
case :P()
}
fclose(stdin);fclose(stdout);
}
codeforces 111C/112E Petya and Spiders的更多相关文章
- 【Codeforces 111C】Petya and Spiders
Codeforces 111 C 题意:给\(n\times m\)的网格,每个点上有一个蜘蛛,每个蜘蛛可以向上.下.左.右走一步或者不动,问最多能存在多少没有蜘蛛的点. 思路1: 首先因为\(n\) ...
- codeforces 111B/112D Petya and Divisors
题目:Petya and Divisors传送门: http://codeforces.com/problemset/problem/111/B http://codeforces.com/probl ...
- codeforces 111A/112C Petya and Inequiations
题目:Petya and Inequiations传送门: http://codeforces.com/problemset/problem/111/A http://codeforces.com/p ...
- cf 85 E. Petya and Spiders
http://codeforces.com/contest/112/problem/E 轮廓线dp.每一个格子中的蜘蛛选一个去向.终于,使每一个蜘蛛都有一个去向,同一时候保证有蜘蛛的格子最少.须要用4 ...
- Petya and Spiders【二进制状压】
题目链接[http://codeforces.com/problemset/problem/111/C] 题意:给出大小为N*M的图(1 ≤ n, m ≤ 40, n·m ≤ 40),每个图中有一个蜘 ...
- Codeforces 1082 G - Petya and Graph
G - Petya and Graph 思路: 最大权闭合子图 对于每条边,如果它选了,那么它连的的两个点也要选 边权为正,点权为负,那么就是求最大权闭合子图 代码: #pragma GCC opti ...
- CF刷题-Codeforces Round #481-G. Petya's Exams
题目链接:https://codeforces.com/contest/978/problem/G 题目大意:n天m门考试,每门考试给定三个条件,分别为:1.可以开始复习的日期.2.考试日期.3.必须 ...
- Codeforces 832 B. Petya and Exam-字符串匹配
补的若干年以前的题目,水题,太菜啦_(:з」∠)_ B. Petya and Exam time limit per test 2 seconds memory limit per test ...
- 【Codeforces 1042D】Petya and Array
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 把a[i]处理成前缀和 离散化. 枚举i从1..n假设a[i]是区间和的a[r] 显然我们需要找到a[r]-a[l]<t的l的个数 即a ...
随机推荐
- CentOS 7命令行安装GNOME、KDE图形界面(成功安装验证)
来源:cnblogs.com/Amedeo 作者:Amedeo 正文 CentOS 7 默认是没有图形化界面的,但我们很多人在习惯了 Windows 的图形化界面之后,总是希望有一个图形化界面从而方 ...
- grpc应用于微服务的分析,基于python
grpc应用于微服务的分析 gRPC 是一个高性能.开源和通用的 RPC 框架,面向移动和 HTTP/2 设计,目前提供 C.Java 和 Go 语言版本,分别是:grpc, grpc-java, g ...
- HTML--JS 表单验证
<html> <head> <title>验证表单</title> <script type="text/javascript" ...
- spring-boot BUG 集锦
BUG1: If you want an embedded database (H2, HSQL or Derby), please put it on the classpath. BUG2:使用 ...
- 《STL源码剖析》——第四章、序列容器
1.容器的概观与分类 所谓序列式容器,其中的元素都可序(ordered)[比如可以使用sort进行排序],但未必有序(sorted).C++语言本身提供了一个序列式容器array,STL另外再提供v ...
- 洛谷 P1546 最短网络 Agri-Net(最小生成树)
题目链接 https://www.luogu.org/problemnew/show/P1546 说过了不复制内容了 显然是个最小生成树. 解题思路 prim算法 Kruskal算法 prim算法很直 ...
- 7、numpy——广播
1.广播的引出 广播(Broadcast)是 numpy 对不同形状(shape)的数组进行数值计算的方式, 对数组的算术运算通常在相应的元素上进行. 如果两个数组 a 和 b 形状相同,即满足 a. ...
- CHEVP算法(Canny/Hough Estimation of Vanishing Points)
这个算法是汪悦在 Lane detection and tracking using B-spline中提出来的.他在这篇论文中主要用的是B-spline模型,这个模型的主要优点是鲁棒性好,可以针对不 ...
- Linux就该这么学07学习笔记
参考链接:https://www.linuxprobe.com/chapter-07.html RAID磁盘冗余阵列 RAID 0 RAID 0技术把多块物理硬盘设备(至少两块)通过硬件或软件的方式串 ...
- 微信小程序(15)--上传图片公用组件(2)
接下来开始写写上传图片的公用组件,可以自定义上传几张图片. chooseImage文件夹里面的index.wxml和index.js,涉及图片上传,删除,预览. <view class=&quo ...