[BOJ 11839] Beautiful row
View as PDF
Submit solution
Assembly, Awk, C, C++, Java, Pascal, Perl, Python, Sed, Text
Points:
3
Time limit:
3.0s
Memory limit:
256M
Problem types
Allowed languages
Ali-Amir wrote N numbers in a row. A row is called beautiful if any two of the neighbour numbers in the row have got the same amount of ones in binary or ternary notations.</p>
Ali-Amir wants to count the number of ways the all given numbers can be written in a beautiful row.
입력 형식
The first line of input file contains integer N (2 ≤ N ≤ 20). The next line contains N non-negative integers not exceeding 109 each.
출력 형식
Output the number of ways the all given numbers can be placed in a beautiful row.
예제 입력
3
5 1 6
예제 출력
2
힌트
In the sample 5 = 123 and 1 = 13, 5 = 1012 and 6 = 1102, thus rows 1 5 6 and 6 5 1 are beautiful.
Comments