当前位置:网站首页>[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);
}
边栏推荐
- 星诺奇科技IPO被终止:曾拟募资3.5亿元 年营收3.67亿
- Mathematics in machine learning -- common probability distribution (XIII): Logistic Distribution
- Specify flume introduction, installation and configuration
- Penetration test information collection - WAF identification
- 2022-2024年CIFAR Azrieli全球学者名单公布,18位青年学者加入6个研究项目
- Test 1234
- helm部署etcd集群
- 287. Find duplicates
- 首先看K一个难看的数字
- node の SQLite
猜你喜欢
监控界的最强王者,没有之一!
This article discusses the memory layout of objects in the JVM, as well as the principle and application of memory alignment and compression pointer
Some understandings of tree LSTM and DGL code implementation
Estimate blood pressure according to PPG using spectral spectrum time depth neural network [turn]
用于远程医疗的无创、无袖带血压测量【翻译】
Easy to use PDF to SVG program
AvL树的实现
Hongke shares | plate by plate ar application in Beijing Winter Olympics
Introduction to the use of SAP Fiori application index tool and SAP Fiori tools
Top command details
随机推荐
使用cpolar建立一个商业网站(1)
Execution process of MySQL query request - underlying principle
朗坤智慧冲刺科创板:年营收4亿 拟募资7亿
Collection of penetration test information -- use with nmap and other tools
DOM Brief
First, look at K, an ugly number
DOM简要
Echart simple component packaging
测试1234
Test 1234
Cobra quick start - designed for command line programs
POJ 2208 six lengths of tetrahedron are known, and the volume is calculated
Method of accessing mobile phone storage location permission under non root condition
Shangsilicon Valley JUC high concurrency programming learning notes (3) multi thread lock
使用block实现两个页面之间的传统价值观
Test 123
SQL injection Foundation
随着MapReduce job实现去加重,多种输出文件夹
Optical blood pressure estimation based on PPG and FFT neural network [translation]
SQL injection - access injection, access offset injection