传送门: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. ORM对单表的增删改查

    表记录的增加: 1)b = Book(name='python', price=99) b.save() 2)Book.objects.create(name='python', price=99) ...

  2. c++复习:STL之容器

    1 STL的string 1 String概念 string是STL的字符串类型,通常用来表示字符串.而在使用string之前,字符串通常是用char*表示的.string与char*都可以用来表示字 ...

  3. Shell编程:小白初步

    shell类型: shell的历史网络上有一大堆,这里就不介绍了.但是我们的Linux系统上是有许多种shell的我们可以查看:使用命令 vi /etc/passwd 可以查看用户对应的shell(其 ...

  4. Pycharm 字体大小快捷方式设置

    1.File->Settings 2.在搜索框搜索increase 点击Increase Font Size(增大字体)右键选择 Add Mouse Shortcut 然后按Ctrl并且鼠标滚轮 ...

  5. 趣味编程:静夜思(Swift版)

    func verticalWriting(txt:String, offset:Int) { Dictionary(grouping: txt.enumerated(), by: {$0.0 % of ...

  6. JSTL的比较运算符有哪些,用例说说它们的作用

    el表达式对应的运算符 等于  ==    eq 不等于  !=    ne 大于  >     gt 小于  <     lt 大于等于  >=    ge 小于等于  <= ...

  7. 使用jQuery+huandlebars遍历数组

    兼容ie8(很实用,复制过来,仅供技术参考,更详细内容请看源地址:http://www.cnblogs.com/iyangyuan/archive/2013/12/12/3471227.html) & ...

  8. Apache tica详述

    Tika是一个内容抽取的工具集合(a toolkit for text extracting).它集成了POI, Pdfbox 并且为文本抽取工作提供了一个统一的界面.其次,Tika也提供了便利的扩展 ...

  9. java.io.Closeable 接口

    package java.io; import java.io.IOException; /** * 关闭数据资源*/public interface Closeable extends AutoCl ...

  10. VC++ 获取系统时间、程序运行时间(精确到秒,毫秒)的五种方法

    1.使用CTime类(获取系统当前时间,精确到秒) CString str; //获取系统时间 CTime tm; tm=CTime::GetCurrentTime();//获取系统日期 str=tm ...