TOJ 4976: 新生数(深搜)
传送门: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: 新生数(深搜)的更多相关文章
- 方格取数(多线程dp,深搜)
https://www.luogu.org/problem/P1004 题目描述 设有N×N的方格图(N≤9),我们将其中的某些方格中填入正整数,而其他的方格中则放入数字0.如下图所示(见样例): 某 ...
- 算法数据结构——数的深搜和广搜(dfs和bfs)
leetcode104 二叉树的最大深度 https://leetcode-cn.com/problems/maximum-depth-of-binary-tree/ 深度搜索分两种:递归(使用栈) ...
- 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 ...
- 2016弱校联盟十一专场10.2---Around the World(深搜+组合数、逆元)
题目链接 https://acm.bnu.edu.cn/v3/problem_show.php?pid=52305 problem description In ICPCCamp, there ar ...
- 2015暑假多校联合---Cake(深搜)
题目链接:HDU 5355 http://acm.split.hdu.edu.cn/showproblem.php?pid=5355 Problem Description There are m s ...
- 深搜+DP剪枝 codevs 1047 邮票面值设计
codevs 1047 邮票面值设计 1999年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description ...
- 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 ...
- 【BZOJ】1016: [JSOI2008]最小生成树计数 深搜+并查集
最小生成树计数 Description 现在给出了一个简单无向加权图.你不满足于求出这个图的最小生成树,而希望知道这个图中有多少个不同的最小生成树.(如果两颗最小生成树中至少有一条边不同,则这两个最小 ...
- 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 ...
随机推荐
- idea 关闭自动保存,未保存星号提醒, springboot + freemarker 热部署
1,自动保存 File > setting 去掉下图勾选 2,未保存文件星号提示 File > Settings 3,spring boot 项目 热部署 3.1,pom文件添加依赖 &l ...
- 静态方法@staticmethod
staticmethod 返回函数的静态方法.该方法不强制要求传递参数,名义上在类里面归类管理,但是不能使用类的变量和实例的变量是类的工具包 如下声明一个静态方法: class Room: t = 1 ...
- 20165304《JAVA程序设计》第四周学习总结
教材内容总结 第五章 子类与继承 1.子类声明中通常用关键字extend来定义一个子类(class 子类名 extend 父类名{}) 2.子类和父类在同一包中的继承性,继承的成员变量或方法的访问权限 ...
- git-搭建企业git服务器
1.安装 yum install git 2.增加用户 useradd git -d /home/git -g git 3.查看公钥鉴权文件是否存在 cat /home/git/.ssh/autho ...
- JAVA8-待续
1. 函数式编程,因为在并发和时间驱动编程中的优势,函数式编程又逐渐流行起来 以前是实现一个比较器需要实现Comparator接口,并重写compare方法,以下为两种实现方法(类似还有线程,事件等) ...
- html lesson one
Review Congratulations on completing the first lesson of HTML & CSS! You are well on your way to ...
- Spark读取配置(转)
转自:https://github.com/keepsimplefocus/spark-sourcecodes-analysis/blob/master/markdowns/Spark%E8%AF%B ...
- 尚硅谷springboot学习10-@PropertySource,@ImportResource,@Bean
@PropertySource 使用指定的属性文件而不一定是application.xxx 同样可以注入相关内容 @ImportResource 导入Spring的配置文件,让配置文件里面的内容生效: ...
- byte类型的127+1=-128?
public class Test2 { public void add(Byte b) { b = b++; } public void test() { Byte a = 127; Byte ...
- overload重载
方法的重载 /** * 重载 overload * @author Administrator *同一个类,同一个方法 *不同:参数列表不同(类型,个数,顺序) 只和 参数列表有关 * 跟 返回值 和 ...