In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "how to achieve sequence sorting on C++". The content of the explanation in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought slowly and deeply. Let's study and learn "how C++ can achieve sequence sorting".
Permutation Sequence sequence sorting
The set [1,2,3,...,n] contains a total of n! Unique permutations.
By listing and labeling all of the permutations in order, we get the following sequence for n = 3:
"123"
"132"
"213"
"231"
"312"
"321"
Given n and k, return the kth permutation sequence.
Note:
Given n will be between 1 and 9 inclusive.
Given k will be between 1 and n! Inclusive.
Example 1:
Input: n = 3, k = 3
Output: "213"
Example 2:
Input: n = 4, k = 9
Output: "2314"
The purpose of this problem is to find out the k permutation and combination of n numbers. because of its particularity, we do not have to find all the permutations and combinations, and then return to the k, here we can only find the k permutation and combination. then the difficulty is how to know the order of the numbers. first of all, we should know that when n = 3, there are 3! = 6 kinds of permutations and combinations, when n = 4. There are 4! = 24 permutations and combinations. Here we will analyze them in the case of n = 4 and k = 17. All permutations and combinations are as follows:
1234
1243
1324
1342
1423
1432
2134
2143
2314
2341
2413
2431
3124
3142
3214
3241
3412 = 1;-- I) {int j = k / f [I-1]; k% = f [I-1]; res.push_back (num1); num.erase (j, 1);} return res;}} Thank you for your reading. the above is the content of "how to achieve sequence sorting on C++". After the study of this article, I believe you have a deeper understanding of the problem of how to achieve sequence sorting on C++. The specific use also needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.