传送门:http://acm.tzc.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=4976

时间限制(普通/Java):1000MS/3000MS     内存限制:65536KByte

描述

我们定义十进制数中有6的为新生数。现在给你一些二进制数,叫你判断是不是新生数。当然这个太简单了,我们换种玩法,给你一个不完全的二进制数,其中有些数字是未知的用x表示,问,这个未知的二进制数最多可以有几种新生数的表示。

输入

输入有多组数据。

每组一行,一个二进制数(长度不超过50,未知的数不超过20)。

输出

每行输出一个数,表示最多可以表示的总数。

样例输入

1xxxxx1111xx0xx
1xx0x1x0x1x0x1x0x1x0x10

样例输出

179
1408

提示

PS:放心没有前导0和x。


思路:

输入字符串,对字符串如果是'x' 则分 x为0或者x为1进行再次深搜。直到整个字符串都是01串(即不包含字符x的时候,return掉就行了)

因为x最多是20,不用担心会爆栈。

然后因为最多是50位,所以数字也不会超过__int64,不用大数

代码:

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
int su;
bool judge(string s){
for(int i = s.size() - ; i >= ; i--){
if(s[i] == 'x')return false;
}
return true;
}
string s;
bool check(__int64 ans){
while(ans){
int sum = ans % ;
if(sum == ) return true;
ans/=;
}
return false;
}
void dfs(int i,__int64 sum,__int64 w){
if(i == -){
if(check(sum))//check函数判断含不含6
su++;
return;
}
if(s[i] == ''){
dfs(i-,sum,w*);
return;
}//sum 不加当前的数
else if(s[i] == ''){
dfs(i-,sum+w,w*);
return;
}//sum 加当前的数
else{
dfs(i-,sum+w,w*);
dfs(i-,sum,w*);
//分两种情况递归下去
return;
}
}
int main()
{
while(cin>>s){
su = ;
int len = s.size();dfs(len-,,);
printf("%d\n",su);
}
}

TOJ 4976: 新生数(深搜)的更多相关文章

  1. 方格取数(多线程dp,深搜)

    https://www.luogu.org/problem/P1004 题目描述 设有N×N的方格图(N≤9),我们将其中的某些方格中填入正整数,而其他的方格中则放入数字0.如下图所示(见样例): 某 ...

  2. 算法数据结构——数的深搜和广搜(dfs和bfs)

    leetcode104 二叉树的最大深度 https://leetcode-cn.com/problems/maximum-depth-of-binary-tree/ 深度搜索分两种:递归(使用栈) ...

  3. 2016弱校联盟十一专场10.3---Similarity of Subtrees(深搜+hash、映射)

    题目链接 https://acm.bnu.edu.cn/v3/problem_show.php?pid=52310 problem description Define the depth of a ...

  4. 2016弱校联盟十一专场10.2---Around the World(深搜+组合数、逆元)

    题目链接 https://acm.bnu.edu.cn/v3/problem_show.php?pid=52305 problem  description In ICPCCamp, there ar ...

  5. 2015暑假多校联合---Cake(深搜)

    题目链接:HDU 5355 http://acm.split.hdu.edu.cn/showproblem.php?pid=5355 Problem Description There are m s ...

  6. 深搜+DP剪枝 codevs 1047 邮票面值设计

    codevs 1047 邮票面值设计 1999年NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond 题目描述 Description ...

  7. hdu 5648 DZY Loves Math 组合数+深搜(子集法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5648 题意:给定n,m(1<= n,m <= 15,000),求Σgcd(i|j,i&am ...

  8. 【BZOJ】1016: [JSOI2008]最小生成树计数 深搜+并查集

    最小生成树计数 Description 现在给出了一个简单无向加权图.你不满足于求出这个图的最小生成树,而希望知道这个图中有多少个不同的最小生成树.(如果两颗最小生成树中至少有一条边不同,则这两个最小 ...

  9. ZOJ(ZJU) 1002 Fire Net(深搜)

    Suppose that we have a square city with straight streets. A map of a city is a square board with n r ...

随机推荐

  1. springboot 前后端分离项目跨域配置

    @Configuration @EnableWebMvc public class CorsConfig implements WebMvcConfigurer { @Override public ...

  2. linux centos7.5修改主机名和ip永久生效

    以centos7.5为例 1.修改主机名 [root@localhost ~]# hostname localhost.localdomain[root@localhost ~]# hostname ...

  3. centos7.5单机yum安装kubernetes

    1.系统配置 centos7.5 docker 1.13.1 centos7下安装docker 2.关闭防火墙,selinux,swapoff systemctl disable firewalld ...

  4. windows下Jenkins环境搭建

    Jenkins简介 Jenkins是一个开源软件项目,业界著名的持续集成工具. Jenkins 安装准备 1.      安装java 并且配置jdk环境 2.      到Jenkins官网下载Je ...

  5. Vmware 不使用物理内存运行缓慢的处理方法

    VMware虚拟机直接使用物理内存的方法 1:打开虚拟机操作系统文件夹,找到.vmx后缀的文件 2:以记事本方式打开文件,在最后一行添加mainMem.useNamedFile=FALSE. 3:保存 ...

  6. APP-8.1-百度语音应用

    1.百度语音登录地址 http://yuyin.baidu.com/ 2.控制台创建应用 3.生成签名 3.1Postman软件应用 APP-8.2-Postman应用 3.2Postman执行 UR ...

  7. 固定顶部指定div不滑动

    .fixed_div { position:fixed; z-index:100; top: 45px; width:100%; height:45px; } 指定div设置属性position:fi ...

  8. const 关键字总结

    int a; const int* p = &a; ==  int const * p = &a; 表示通过p不能修改a的值. const int a; int *p = &a ...

  9. linux下svn不能连接上windows服务器:SSL handshake failed: SSL error

    在linux服务器下载https链接的svn源码时出现:SSL handshake failed: SSL error: Key usage violation in certificate has ...

  10. CocosCreator 自定义TypeScript在VsCode的提示数据

    在assets文件夹外新建xx.d.ts文件如:global.d.ts global.d.ts declare class UserData{ node:cc.Node; name:string; } ...