当前位置:网站首页>[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);
}
边栏推荐
- Coco2017 dataset usage (brief introduction)
- None of the strongest kings in the monitoring industry!
- Brief description of SQL optimization problems
- Grafana 9.0 is officially released! It's the strongest!
- Penetration test information collection - App information
- Implementation of AVL tree
- SAP Fiori 应用索引大全工具和 SAP Fiori Tools 的使用介绍
- POJ 2208 已知边四面体六个长度,计算体积
- Example of implementing web server with stm32+enc28j60+uip protocol stack
- 深度循环网络长期血压预测【翻译】
猜你喜欢
美庐生物IPO被终止:年营收3.85亿 陈林为实控人
被疫情占据的上半年,你还好么?| 2022年中总结
Execution process of MySQL query request - underlying principle
徐翔妻子应莹回应“股评”:自己写的!
Splay
[the 300th weekly match of leetcode]
Describe the process of key exchange
Splay
About NPM install error 1
Numerical analysis: least squares and ridge regression (pytoch Implementation)
随机推荐
openmv4 学习笔记1----一键下载、图像处理背景知识、LAB亮度-对比度
DOM简要
Medical image segmentation
Introduction and case analysis of Prophet model
Stm32+mfrc522 completes IC card number reading, password modification, data reading and writing
node の SQLite
Describe the process of key exchange
Example of implementing web server with stm32+enc28j60+uip protocol stack
Easy to use PDF to SVG program
The role of applet in industrial Internet
Jushan database was among the first batch of financial information innovation solutions!
Handwritten online chat system (principle part 1)
[Sun Yat sen University] information sharing of postgraduate entrance examination and re examination
Visual Studio Code启动时提示“Code安装似乎损坏。请重新安装。”、标题栏显示“不受支持”信息的解决办法
Cocos2d Lua smaller and smaller sample memory game
Hongke shares | plate by plate ar application in Beijing Winter Olympics
First, look at K, an ugly number
bonecp使用数据源
Wchars, coding, standards and portability - wchars, encodings, standards and portability
朗坤智慧冲刺科创板:年营收4亿 拟募资7亿