程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

[Python implementation of Huawei machine test] dynamic planning - how to write a recursive function

編輯:Python

List of articles

  • Preface
  • How to write a recursive function
  • DP2 Skip step
  • Little rabbits breed


Preface

《 Huawei machine test real problem 》 The column includes Huawei column of niuke.com 、 Huawei test questions 、 Huawei OD Real problem of machine test .

If you are preparing for Huawei's interview , If you want to know something, you can send me a private letter , I will try my best to help you , I can also give you some suggestions !

This paper solves the non optimal solution ( Non optimal performance ).

How to write a recursive function

Students who have read the last article may also find , Recursive function is a good method to solve dynamic programming problems , So how do we write a recursive function ?

If a function is executing , Call yourself directly or indirectly , We call it a recursive function .

Recursive application scenarios , List operation 、 Binary tree operation 、 Permutation and combination problems and dynamic programming problems , One of their characteristics is that as the recursion depth increases , The scale of the problem is decreasing .

For example, we are in the auditorium where the school reports the performance , You want to know what you will do in which row ?
Scheme 1 : Go to the first row and count to your row .
Option two : Ask the students in the front row what row they are in , On his basis +1 Is the current number of rows , If the previous row is not clear, ask him again , Until I asked the students in the first row .

This is a simple recursive function :


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved