当前位置:网站首页>[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);
}
边栏推荐
- Picture zoom Center
- About NPM install error 1
- Some understandings of tree LSTM and DGL code implementation
- 使用map函数、split函数一行键入多个元素
- Hongke shares | plate by plate ar application in Beijing Winter Olympics
- Reproduce ThinkPHP 2 X Arbitrary Code Execution Vulnerability
- Self supervised heterogeneous graph neural network with CO comparative learning
- Grafana 9.0 is officially released! It's the strongest!
- Human bone point detection: top-down (part of the theory)
- AFNetworking框架_上传文件或图像server
猜你喜欢
Easy to use PDF to SVG program
CSRF漏洞分析
同宇新材冲刺深交所:年营收9.47亿 张驰与苏世国为实控人
44 colleges and universities were selected! Publicity of distributed intelligent computing project list
None of the strongest kings in the monitoring industry!
Noninvasive and cuff free blood pressure measurement for telemedicine [translation]
根据PPG估算血压利用频谱谱-时间深度神经网络【翻】
287. 寻找重复数
Grafana 9.0 is officially released! It's the strongest!
Splay
随机推荐
Stm32+esp8266+mqtt protocol connects onenet IOT platform
CSRF vulnerability analysis
首先看K一个难看的数字
Penetration test information collection - App information
[Sun Yat sen University] information sharing of postgraduate entrance examination and re examination
Coco2017 dataset usage (brief introduction)
Self-supervised Heterogeneous Graph Neural Network with Co-contrastive Learning 论文阅读
徐翔妻子应莹回应“股评”:自己写的!
当保存参数使用结构体时必备的开发技巧方式
基于ppg和fft神经网络的光学血压估计【翻译】
Automatic reservation of air tickets in C language
上海部分招工市場對新冠陽性康複者拒絕招錄
atcoder它A Mountaineer
Huawei 0 foundation - image sorting
wx小程序学习笔记day01
node の SQLite
图片缩放中心
Penetration test information collection - CDN bypass
Cobra quick start - designed for command line programs
Penetration test information collection - site architecture and construction