Hangzhou Electric Acm1027--ignatius and the Princess II

Source: Internet
Author: User

This question, looked for a long time, did not find what the law, Baidu after, only know is the number of the smallest permutation is the first of the enumeration.

What a long knowledge!! ~


Knowing this rule, you can quickly write, algorithm this header file in another enumeration of the function next_permutation, the smallest permutation of the first, is called Next_permutation I-1 times after the arrangement . The same applies to next_permutation, which means that there are duplicate elements in the set.


The following is the code for AC:

#include <iostream> #include <algorithm>using namespace Std;int main () {int n, m, P[1005];while (CIN >> N >> m) {for (int i = 0; i < n; i++) P[i] = i + 1;m--;while (m--) {next_permutation (p, p + N);} for (int j = 0; J < N; j + +) J = = N-1? printf ("%d\n", P[j]): printf ("%d", P[j]);} return 0;}


Hangzhou Electric Acm1027--ignatius and the Princess II

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.