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 ...
随机推荐
- iframe父窗口和子窗口的调用方法
iframe 父窗口和子窗口的调用方法父窗口调用子窗口 iframe_name.iframe_document_object.object_attribute = attribute_value 例子 ...
- Activation Functions and Their Derivatives
1. Sigmoid Function: when z=0,g'(z)=0.25 2. tanh Function: when x=0,tanh'(x)=1 3. Relu
- c语言自带的排序与查找
qsort与bsearch qsort(元素起始地址,元素总数,单个元素的大小,比较函数) bsearch(key元素地址,元素起始地址,元素总数,单个元素的大小,比较函数) 比较函数: 原型为int ...
- IDF-CTF-简单的js加密 writeup
题目链接: http://ctf.idf.cn/index.php?g=game&m=article&a=index&id=43 知识点:js语法 这里这里→ http://c ...
- MyEclipse停止自带插件的启动
MyEclipse启动时因为自身带有很多的插件,所以在启动时运行的速度特别慢,所以可以选择一下启动时的插件,将不使用的插件选择在MyEclipse启动时不起动. 步骤如下: windows->p ...
- hdu6333 Problem B. Harvest of Apples(组合数+莫队)
hdu6333 Problem B. Harvest of Apples 题目传送门 题意: 求(0,n)~(m,n)组合数之和 题解: C(n,m)=C(n-1,m-1)+C(n-1,m) 设 ...
- Centos 7.6安装mysql服务端5.7
环境:centos 7.6,mysql server 5.7.26 新建文件夹/opt/mysql,并cd进去 运行wget http://dev.mysql.com/get/mysql-5.7.26 ...
- supermap idesktop连接oraclesptial数据源
1.要使用相同的版本,如iServer 9D, iDesktop9D ,32位的 plsql,32位的 oracleinstance_client 11g 2.当时遇到的问题是使用oracleinst ...
- C#实现百度ping功能
网站优化必做的事情之一,百度ping,主动推送给百度 文章添加时调用百度推送方法 //保存 protected void btnSubmit_Click(object sender, EventArg ...
- jsp页面必填项如何加红星号*
1.加*号 并且设置*号大小 <span style="color:red; font-size: 20px">*</span>