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

The question :
Given a string , Find the separation scheme , Separate the string into non repeating numbers
Ideas :
Because the string length is less than 100, therefore n yes 2 digit .
You can separate them in groups , You can also work in groups of two
( It can be seen as walking through a one-dimensional maze , from S[0] Go to the S[n-1], One step at a time , Or take two steps .)
DFS(int index)// The subscript
prune :
(1) Feasibility pruning ( Transboundary ):if(index>=n)return;
(2) Repetitive pruning (vis Array ): If there have been numbers , There is no need to search
(3) Optimal pruning ( With global variables flag): If there is already a set of solutions , Then there is no need to search
To make a choice :
Mark the number
Digital join vector Array
DFS(index+1)// Take a step
Recall mark
vector.pop_back();
Mark the number
Digital join vector Array
DFS(index+2)// Take two steps
Recall mark
vector.pop_back();
#include<iostream>
#include<string>
#include<vector>
using namespace std;
bool vis[100];
vector<int>num;
string s;
int n;
bool flag=false;
void dfs(int step){
if(flag){
return;
}
if(step>=s.size()){
for(int i=0;i<num.size();i++){
cout<<num[i]<<" ";
}
flag=true;
return;
}
if(!vis[s[step]-'0']){
vis[s[step]-'0']=true;
num.push_back(s[step]-'0');
dfs(step+1);
vis[s[step]-'0']=false;
num.pop_back();
}
if((s[step]-'0')!=0&&!vis[(s[step]-'0')*10+s[step+1]-'0'])
{
vis[(s[step]-'0')*10+s[step+1]-'0']=true;
num.push_back((s[step]-'0')*10+s[step+1]-'0');
dfs(step+2);
vis[(s[step]-'0')*10+s[step+1]-'0']=false;
num.push_back((s[step]-'0')*10+s[step+1]-'0');
}
}
int main(){
cin>>s;
dfs(0);
}边栏推荐
- POJ 2208 six lengths of tetrahedron are known, and the volume is calculated
- SAP Fiori 应用索引大全工具和 SAP Fiori Tools 的使用介绍
- Picture zoom Center
- Describe the process of key exchange
- Atcoder a mountaineer
- 测试1234
- Noninvasive and cuff free blood pressure measurement for telemedicine [translation]
- Introduction to the use of SAP Fiori application index tool and SAP Fiori tools
- openmv4 学习笔记1----一键下载、图像处理背景知识、LAB亮度-对比度
- Epoll () whether it involves wait queue analysis
猜你喜欢
随机推荐
Self supervised heterogeneous graph neural network with CO comparative learning
用友OA漏洞学习——NCFindWeb 目录遍历漏洞
爬虫玩得好,牢饭吃到饱?这3条底线千万不能碰!
CSRF漏洞分析
朗坤智慧冲刺科创板:年营收4亿 拟募资7亿
Epoll () whether it involves wait queue analysis
First, look at K, an ugly number
Introduction to the use of SAP Fiori application index tool and SAP Fiori tools
STM32+ENC28J60+UIP协议栈实现WEB服务器示例
Cocos2d Lua 越来越小样本 内存游戏
Deep circulation network long-term blood pressure prediction [translation]
Reproduce ThinkPHP 2 X Arbitrary Code Execution Vulnerability
AcWing 3537.树查找 完全二叉树
epoll()无论涉及wait队列分析
Crawling data encounters single point login problem
Video based full link Intelligent Cloud? This article explains in detail what Alibaba cloud video cloud "intelligent media production" is
[the 300th weekly match of leetcode]
Installation and management procedures
人体骨骼点检测:自顶向下(部分理论)
SQL injection - access injection, access offset injection








