当前位置:网站首页>Other application examples of backtracking method
Other application examples of backtracking method
2022-07-21 08:43:00 【Harris Henry】
In the previous section, we focused on the problem of backtracking prime rings . This section will briefly introduce several other application examples of backtracking .
Catalog
Difficult string Krypton Factor, Uva 129
bandwidth Bandwidth, Uva 140
This topic is about giving a n A graph of nodes G And an arrangement of nodes , node i The bandwidth of the b(i) by i And the farthest distance in the arrangement of adjacent nodes in the original figure , And all nodes b(i) The maximum value of is the bandwidth of the whole graph . The node arrangement that requires a given graph to minimize its bandwidth .
The simplest idea is to recursively enumerate all permutations , But obviously, the amount of calculation is too large , Moreover, there are no obvious constraints like the eight queens problem that can make some nodes interrupt and extend in advance .
In fact, optimization methods can still be found —— Record the minimum bandwidth currently found k, If it is found that the distance between two nodes is greater than or equal to k, Then the arrangement cannot be better than the solution of the current record , So it can be terminated decisively . In the solution tree, it is called “ prune ”(prune).
besides , According to the mathematical relationship of nodes , There is m Nodes of adjacent nodes u, Ideally, these adjacent nodes are u Back , Make the bandwidth m. So if m≥ At present k, Then the permutation can't get a better solution anyway .
Difficult string Krypton Factor, Uva 129
The difficult string refers to “ A string that does not contain two adjacent repeated substrings ”, such as D,DC,ABDAB etc. .... The title requires a positive integer n and L, The output is preceded by the alphabet L Letter composition 、 Dictionary preface No n Small “ Difficult string ”.
Because only “ adjacent ” The substring of is counted into , So you only need to judge the suffix of the current string, not the whole string :
int dfs(int cur){
if(cnt++ ==n){
for(int i=0;i<cur;i++)
printf("%c",'A'+S[i]); // Output
printf("\n");
return 0;
}
for(int i=0;i<L;i++){
S[cur]=i;
int ok=1;
for(int j=1;j*2<=cur+1;j++){
int equal=1;
for(int k=0;k<j;k++)
if(S[cur-k]!=S[cur-k-j]){ equal=0;break; }
if(equal){ ok=0;break; } // The first half is equal to the second half , illegal
}
if(ok) if(!dfs(cur+1)) return 0;
}
return 1;
}
End of today , Clear the learning path to find problems
边栏推荐
- 探究路径寻找问题BFS结点的判重方法
- Highlight first! 2022 open atom global open source summit is scheduled to be held in Beijing on July 25-29
- JS 将伪数组转换成数组
- 懒到骨子里了,我在CSDN写文章都懒得自己写了,基于selenium模拟写文章
- Selenium uploads files locally to web pages
- How much do you know about the questions often asked by redis in Alibaba's interview?
- 六.uniapp[闪屏页加载方式、闪屏页设置]
- Google lance une autre bataille pour construire des noyaux, rejoignant Intel, un vétéran de 17 ans
- Rsync combined with inotify to realize real-time file synchronization (I)
- Web vulnerability security - invalid access control
猜你喜欢
编程语言之父们退休太无聊,纷纷选择重返职场
PHP渗透测试文件包含漏洞与利用的方法
【漏洞复现】Apache Log4j2 远程代码执行漏洞
除了定时器,真的没法在Simulation Node 类型的CAPL节点中实现延时了吗?
Redis - 管理工具 redis-cli 详解
水调歌头·明月几时有
How to write the docker cleaning cache script
Starting from scratch, C language intensive Part 1: getting to know C language
Safety day 3 after class practice
selenium从本地上传文件到网页
随机推荐
如何关闭页面之前清空LocalStorage
三维点云课程(五)——深度学习
UML sequence diagram / sequence diagram / sequence diagram
HJ107 solve cube root
Scala 高阶(七):集合内容汇总(上篇)
行业现状令人失望,工作之后我又回到UC伯克利读博了
How many months did you write your first SCI?
这款IDE插件3.0让你成为公司最懂安全的程序员
Leetcode 322 coin change, the minimum number of change
Spatial noise reduction and time domain noise reduction
四.uni-app组件[视图组件、基本内容(官方自带例如表单类)、UI组件库、组件库的坑]
Chapter3 : Fighting COVID-19 with Artificial Intelligence
分布式事务
[freeswitch development practice] using ESL to connect freeswitch in C language
MySQL Basic (Multi - table query, transaction)
Canoe cannot automatically identify serial port number? Then encapsulate a DLL so that it must work
3D point cloud course (V) - in depth learning
探究路径寻找问题BFS结点的判重方法
Google 為造芯再掀“搶人大戰”,英特爾 17 年老將加入
Selenium uploads files locally to web pages