Nyoj 139: What kind of comfort chart do I have?

Source: Internet
Author: User

Question link: http://acm.nyist.net/JudgeOnline/problem.php? PID = 1, 139

 

Train of Thought: What is the typical application of the Kanto expansion, for example. There are a total of six types of numbers 1, 2, and 3. In the dictionary order, the sequence "3, 2, 1" is in the nth order. Kanto thinks like this:

First, we can see from the first 3 that there are 2, 1 smaller than 3, that is to say, if the first is 1 or 2 before this sequence, so what are the sequences starting with 1 or 2? The answer is 2*2 !. Why is this answer? Because there are two numbers in the first and second places that meet the requirements, and the total number of the second and third places is 2 !, Therefore, all those who have learned how to arrange and combine them can simply multiply them (the Kanto expansion was originally included in the composite mathematics ...).

 

Now that we understand what the Kanto expansion is, we can write the code below.

 

The Code is as follows:

  

# Include <iostream> # include <cstring> using namespace STD; int JC [] = {120,720,504, 39916800,}; // factorial array, record the factorial int book [12] = {0}; // mark the array, marking whether int main () {string temp has been used; // test data int num; int now; // use int res only as an intermediate variable; // result int X; // a number that is smaller than the current element and has not been used CIN> num; while (Num --) {memset (book, 0, sizeof (book); // The minimum initialization result is 1 res = 1; CIN> temp; for (INT I = 0; I <12; I ++) {x = 0; now = temp [I]-97; // mark the current temp [I] That has used book [now] = 1; // start to find several for (Int J = 0; j <11; j ++) elements smaller than the current temp [I) {If (Book [J] = 0 & now> J) x ++;} // Add the result. Res + = JC [10-i] * X ;} cout <res <Endl;} return 0 ;}

The Code is fully explained. I personally feel that this question is just a template, and I do not know what kind of function is used in algorithm competitions .. I hope the experts can tell me what the Kanto expansion can do ~

Nyoj 139: What kind of comfort chart do I have?

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.