当前位置:网站首页>[depth first search] Ji suanke: find numbers
[depth first search] Ji suanke: find numbers
2022-07-06 18:46:00 【muse_ age】

dfs(num) The current number is num
The first is 1, Then everyone can choose 0 perhaps 1.
DFS(num *10);// choice 0 after num
DFS(num*10+1);// choice 1 after num
Because the question in the question is whether it exists , Then we can stop searching after finding a solution .
Pruning operation :
Define a bool Global variables flag, When a solution is found ,flag Set up true,
prune :
if(flag){return;}
Code :
Use it carefully long long
#include<iostream>
using namespace std;
int n;
bool flag;
void dfs(long long num){
if(flag==true){
return;
}
if(num%n==0){
cout<<num<<endl;
flag=true;
return;
}
dfs(num*10);
dfs(num*10+1);
}
int main(){
flag=false;
cin>>n;
dfs(1);
}边栏推荐
- 10、 Process management
- Specify flume introduction, installation and configuration
- 线代笔记....
- 44 colleges and universities were selected! Publicity of distributed intelligent computing project list
- POJ 2208 已知边四面体六个长度,计算体积
- Numerical analysis: least squares and ridge regression (pytoch Implementation)
- Top command details
- Atcoder a mountaineer
- AFNetworking框架_上传文件或图像server
- 【LeetCode第 300 场周赛】
猜你喜欢

手写一个的在线聊天系统(原理篇1)

Hongke shares | plate by plate ar application in Beijing Winter Olympics

【LeetCode第 300 场周赛】

About NPM install error 1
![Noninvasive and cuff free blood pressure measurement for telemedicine [translation]](/img/56/8deaec18cd9f2cf49ff234b09b1283.png)
Noninvasive and cuff free blood pressure measurement for telemedicine [translation]

深度循环网络长期血压预测【翻译】

This article discusses the memory layout of objects in the JVM, as well as the principle and application of memory alignment and compression pointer

徐翔妻子应莹回应“股评”:自己写的!

Medical image segmentation

一种用于夜间和无袖测量血压手臂可穿戴设备【翻译】
随机推荐
具体说明 Flume介绍、安装和配置
监控界的最强王者,没有之一!
图片缩放中心
JDBC驱动器、C3P0、Druid和JDBCTemplate相关依赖jar包
Collection of penetration test information -- use with nmap and other tools
openmv4 学习笔记1----一键下载、图像处理背景知识、LAB亮度-对比度
测试1234
解读云原生技术
POJ 2208 已知边四面体六个长度,计算体积
AFNetworking框架_上传文件或图像server
There is a sound prompt when inserting a USB flash disk under win10 system, but the drive letter is not displayed
Noninvasive and cuff free blood pressure measurement for telemedicine [translation]
Visual Studio Code启动时提示“Code安装似乎损坏。请重新安装。”、标题栏显示“不受支持”信息的解决办法
爬虫玩得好,牢饭吃到饱?这3条底线千万不能碰!
CSRF漏洞分析
C#/VB.NET 给PDF文档添加文本/图像水印
Summary of performance knowledge points
Estimate blood pressure according to PPG using spectral spectrum time depth neural network [turn]
Deep circulation network long-term blood pressure prediction [translation]
How are you in the first half of the year occupied by the epidemic| Mid 2022 summary