题目: 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的更多相关文章

  1. 【Codeforces 111C】Petya and Spiders

    Codeforces 111 C 题意:给\(n\times m\)的网格,每个点上有一个蜘蛛,每个蜘蛛可以向上.下.左.右走一步或者不动,问最多能存在多少没有蜘蛛的点. 思路1: 首先因为\(n\) ...

  2. codeforces 111B/112D Petya and Divisors

    题目:Petya and Divisors传送门: http://codeforces.com/problemset/problem/111/B http://codeforces.com/probl ...

  3. codeforces 111A/112C Petya and Inequiations

    题目:Petya and Inequiations传送门: http://codeforces.com/problemset/problem/111/A http://codeforces.com/p ...

  4. cf 85 E. Petya and Spiders

    http://codeforces.com/contest/112/problem/E 轮廓线dp.每一个格子中的蜘蛛选一个去向.终于,使每一个蜘蛛都有一个去向,同一时候保证有蜘蛛的格子最少.须要用4 ...

  5. Petya and Spiders【二进制状压】

    题目链接[http://codeforces.com/problemset/problem/111/C] 题意:给出大小为N*M的图(1 ≤ n, m ≤ 40, n·m ≤ 40),每个图中有一个蜘 ...

  6. Codeforces 1082 G - Petya and Graph

    G - Petya and Graph 思路: 最大权闭合子图 对于每条边,如果它选了,那么它连的的两个点也要选 边权为正,点权为负,那么就是求最大权闭合子图 代码: #pragma GCC opti ...

  7. CF刷题-Codeforces Round #481-G. Petya's Exams

    题目链接:https://codeforces.com/contest/978/problem/G 题目大意:n天m门考试,每门考试给定三个条件,分别为:1.可以开始复习的日期.2.考试日期.3.必须 ...

  8. Codeforces 832 B. Petya and Exam-字符串匹配

    补的若干年以前的题目,水题,太菜啦_(:з」∠)_    B. Petya and Exam   time limit per test 2 seconds memory limit per test ...

  9. 【Codeforces 1042D】Petya and Array

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 把a[i]处理成前缀和 离散化. 枚举i从1..n假设a[i]是区间和的a[r] 显然我们需要找到a[r]-a[l]<t的l的个数 即a ...

随机推荐

  1. Run Your Tensorflow Deep Learning Models on Google AI

    People commonly tend to put much effort on hyperparameter tuning and training while using Tensoflow& ...

  2. 【报错】The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

    提交表单之后, 报错页面显示: HTTP Status 404 – 未找到 Type Status Report 消息 Not found 描述 The origin server did not f ...

  3. C++ std::isnan等函数的使用

    C和C++11标准提供了类似于isnan.isfinite.isinf.isnormal.fpclassify分别用于判断是非数(NaN)值.有限制.无穷值.正常数值等. 今天在使用Modbus读取设 ...

  4. composer 版本号前置~与^符号的区别

    语义化版本https://semver.org/lang/zh-CN/ 了解版本号分 所以用这个说法来理解composer.json里面版本的控制

  5. [Bzoj1008][HNOI2008]越狱(组合计数)

    题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1008 组合计数的简单题,可能越狱的方案数等于总方案数-不可能越狱的方案数,则: 总方案数 ...

  6. 洛谷 P1440 求m区间内的最小值(单调队列)

    题目链接 https://www.luogu.org/problemnew/show/P1440 显然是一道单调队列题目…… 解题思路 对于单调队列不明白的请看这一篇博客:https://www.cn ...

  7. BZOJ 4675(点分治)

    题面 传送门 分析 由于期望的线性性,我们可以分别计算每个点对对答案的贡献 有三个人取数字,分开对每个人考虑 设每个人分别取了k个数,则一共有\(C_n^k\)种组合,选到每种组合的概率为\(\fra ...

  8. 76.Longest Consecutive Sequence(最长的连续序列)

    Level:   Hard 题目描述: Given an unsorted array of integers, find the length of the longest consecutive ...

  9. sig文件制作

    一 配置环境变量 将link.exe,pcf.exe,sigmake.exe添加进PATH环境变量(选择“我的电脑” >“属性”>“高级” >“环境变量”>将文件地址添加进“p ...

  10. JWT 实现基于API的用户认证

    基于 JWT-Auth 实现 API 验证 如果想要了解其生成Token的算法原理,请自行查阅相关资料 需要提及的几点: 使用session存在的问题: session和cookie是为了解决http ...