NYOJ139 the number (string decoding)

Source: Internet
Author: User

NYOJ139 the number (string decoding)

 

Now there are 12 characters in abcdefghijkl. Sort all of them in Lexicographic Order and give any sort. Which of the following is the smallest of all the arrays?

The first line of the input has an integer n (0 Then there are n rows, each row is an arrangement; the output is an integer m, occupying a row, m indicates the number of places in the arrangement; example Input
3abcdefghijklhgebkflacdjigfkedhjblcia
Sample output
1302715242260726926

 

Question Analysis:

Do you have any questions about this question? I have answered them in the algorithm getting started classic,For each character s, if k characters are less than s, the sorting of the current sequence will increase k * f [12-i].

AC code:

 

/*** Returns a string that consists of only ~ L composition, each occurrence, returns the lexicographic size of the string * for each character s, if k characters are less than s after it, then the sorting of the current sequence will increase k * f [12-i] * Where f is the factorial of each number and I is the position of s. Therefore, you only need to simulate each bit for comparison. */# Include
    
     
# Include
     
      
# Include
      # Include
       
        
# Include
        
         
# Include
         
           # Include
          
            # Include
           
             # Include
            
              # Include
             
               # Include
              
                # Include
               
                 Using namespace std; int main () {long f [15]; f [1] = 1; for (int I = 2; I <= 12; I ++) {f [I] = f [I-1] * I;} char s [15]; int t; scanf (% d, & t); while (t --) {scanf (% s, s + 1); long sum = 0; for (int I = 1; I <= 12; I ++) {int k = 0; for (int j = I + 1; j <= 12; j ++) {if (s [I]> s [j]) k ++ ;} sum + = f [12-i] * k;} printf (% lld, sum + 1);} return 0 ;}
               
              
             
            
           
          
         
        
       
     
    


 

 


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.