In addition to Weibo, there is also WeChat
Please pay attention

WeChat public account
Shulou
2025-11-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "how to use K-th grammar". In daily operation, I believe many people have doubts about how to use K-th grammar. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubts about "how to use K-th grammar"! Next, please follow the editor to study!
The title is that there are only 0 or 1 elements in a row, and the next line is the current transformation. The element of 0 becomes 01 and the element of 1 becomes 10.
For example, then give the number of rows N, and the number of horizontal digits K, which element is 0 or 1.
For example, it is given below that N is 4 and K is 5, and that element is 1.
Explanation:
Row 1: 0 row 2: 01 row 3: 0110 row 4: 01101001
In fact, this problem is in a sense a simple version of the Pascal triangle, if the head iron layer by layer recursive down of course, but the efficiency is too low.
Analyzed below, in fact, for the horizontal digit K of the current row, it is the transformation of the element of the previous line rounding up the 2 bits of Kpicer, if the previous one is 0, it is 0 or 1, if it is not even, it is 0, if the even number is 1; for 1, the non-even number is 1, and the even number is 0. According to this principle, it can be recursive.
The code is as follows, int ((Know1) / 2) is to round up.
Class Solution: def kthGrammar (self, N: int, K: int)-> int: defuatN = 4 defautRow = '01101001' if K < 8: return int (defautRows [K-1]) else: if K% 2 = = 1: re = self.kthGrammar Int ((Kwon 1) / 2) else: re = 0 if self.kthGrammar ((Kwon 1) / 2)) = = 1 else 1 return re so far The study on "how to use K-th grammar" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope





About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.