首页 技术 正文
技术 2022年11月7日
0 收藏 620 点赞 530 浏览 1377 个字

考试的时候一看是河南省选题,觉得会很难,有点不敢想正解。感觉是个状压。但是一看是十年前的题,那怂什么!

直接把十六个数的状态压进去,因为个数是不变的,所以状态枚举的时候只要找数目一样的转移即可。而且只需找这一位为1的转移即可。因为个数不变,所以转移0到1和转移1到0是一样的。

就是简单的模拟转移,找它的上下左右对应的那一位是否为0,如果是,那么就是从此为是0,那一位是1转移过来的,取个min即可。

因为枚举是暴力枚举,而不是按状态顺序枚举,所以可能在一次枚举的时候有的状态没有转移到,那就重复处理此过程,直到都转移到即可。

比较暴力。能过就行。hhh。

#include<iostream>#include<cstdio>#include<cstring>using namespace std;#define pos(i,a,b) for(int i=(a);i<=(b);i++)#define pos2(i,a,b) for(int i=(a);i>=(b);i--)int f[1<<16];int count(int x){int sum=0;while(x){if(x&1)  sum++;x>>=1;}return sum;}int tmp,cnt,ans;int flag[20];int main(){freopen("movea.in","r",stdin);freopen("movea.out","w",stdout);memset(f,0x7f,sizeof(f));//cout<<(7^2)<<endl;pos(i,1,16){  char x;  cin>>x;  int xx=x-'0';  if(xx==1)  {tmp|=(1<<((17-i)-1));flag[i]=1;}}pos(i,1,16){  char x;  cin>>x;  int xx=x-'0';  if(xx==1)ans|=(1<<((17-i)-1));}cnt=count(tmp);f[tmp]=0;while(f[ans]>10000000){pos(i,0,(1<<16)-1){if(count(i)==cnt){pos(j,1,16){int qian=(1<<((17-j)-1));if(qian&i){if(((j%4)!=1)&&((1<<((18-j)-1))&i)==0){int temp;temp=(1<<((18-j)-1))|i;temp^=qian;f[i]=min(f[i],f[temp]+1);}if((j%4)&&((1<<((16-j)-1))&i)==0){int temp;temp=(1<<((16-j)-1))|i;temp^=qian;f[i]=min(f[i],f[temp]+1);}if(j<=12&&((1<<((13-j)-1))&i)==0){int temp;temp=(1<<((13-j)-1))|i;temp^=qian;f[i]=min(f[i],f[temp]+1);}if(j>=5&&(((1<<(21-j)-1))&i)==0){int temp;temp=(1<<((21-j)-1))|i;temp^=qian;f[i]=min(f[i],f[temp]+1);}}}}}}cout<<f[ans];//while(1);return 0;}

  

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,156
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,624
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,468
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,240
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,876
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,043