ZOJ 3675 Trim the Nails
来源:互联网 发布:会声会影x9激活软件 编辑:程序博客网 时间:2024/06/05 19:27
状态压缩+暴搜
trick点:指甲剪可以反着剪
#include<cstdio>#include<iostream>#include<cstring>#include<queue>using namespace std;#define LL long longstruct State{int state,step;State(int sta=0,int ste=0){state=sta;step=ste;}};LL cli1;LL cli2;int n,m;int vis[1<<21];int bfs(){State tmp;memset(vis,0,sizeof(vis));queue<State> q;q.push(State(0,0));vis[0]=1;while(!q.empty()){State u=q.front();q.pop();if(u.state==((1<<m)-1))return u.step;for(int i=0;i<m;i++){tmp=u;tmp.state|=((cli1<<i)&((1<<m)-1));if(vis[tmp.state]==0){tmp.step++;vis[tmp.state]=1;q.push(tmp);}tmp=u;tmp.state|=((cli2<<i)&((1<<m)-1));if(vis[tmp.state]==0){tmp.step++;vis[tmp.state]=1;q.push(tmp);}}for(int i=0;i<n;i++){tmp=u;tmp.state|=((cli1>>i)&((1<<m)-1));if(vis[tmp.state]==0){tmp.step++;vis[tmp.state]=1;q.push(tmp);}tmp=u;tmp.state|=((cli2>>i)&((1<<m)-1));if(vis[tmp.state]==0){tmp.step++;vis[tmp.state]=1;q.push(tmp);}}}}int main(){char str[100];while(cin>>n){cin>>str;cli1=cli2=0;for(int i=0;i<n;i++){if(str[i]=='*'){cli1|=1<<i;cli2|=1<<(n-i-1);}}cin>>m;if(cli1==0)cout<<-1<<endl;elsecout<<bfs()<<endl;}return 0;}
- ZOJ 3675 Trim the Nails
- ZOJ 3675 Trim the Nails
- ZOJ 3675 Trim the Nails 小水题
- ZOJ 3675(Trim the Nails)
- ZOJ 3675 Trim the Nails(DFS)
- ZOJ 3675 Trim the Nails(bfs)
- ZOJ 3675 Trim the Nails (状态压缩+BFS)
- ZOJ 3675 Trim the Nails(状态压缩 + BFS)
- ZOJ 3675 Trim the Nails(bfs+位运算处理)
- zoj 3675 Trim the Nails (BFS+状态压缩)
- ZOJ 3675 Trim the Nails(bfs+状态压缩搜索)
- ZOJ3675:Trim the Nails
- BNU Summer Training 2014.08.26 JZOJ Problem Set - 3675 Trim the Nails
- Trim the Nails (DFS+状态压缩) #by Plato
- the usage of String.trim()
- hdu4393Throw nails
- trim()
- Trim
- CCHttpClient发送数据时断网导致闪退的解决方法
- 消费税税款计算
- android DevAppsDirect开源项目
- Settings中下级目录小箭头效果的实现
- .net中Web应用程序和web网站的区别
- ZOJ 3675 Trim the Nails
- yum 安装过程下载的包存放路径
- Spring mvc + Spring Security 拦截 Restful格式的URL并进行验证,支持Remember me token数据库存储
- android pull解析器
- windows下绑定线程(进程)到指定的CPU核心
- 学习jQuery formValidator
- 三、创建 event_base
- IOS UILabel 文字描边详解
- 如何绘制precision——recall曲线和confusion矩阵