아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

We Need More Managers!

시간 제한20초메모리 제한512 MB

요약
길이 n인 서로 다른 이진 문자열 m개가 주어질 때, 모든 정점을 포함하는 루트 트리를 만들어 부모와 자식 사이 해밍 거리의 합이 최소가 되도록 해야 한다.
난이도

보통10점 중 7점

유형
최소 신장 트리, 그래프, 비트 연산, 그리디
정답자
아직 제출이 없습니다

문제

The media company you are working at intends to replace its flat organizational structure (no bosses) with a hierarchical one. A CEO will be chosen, to whom everyone else, directly or indirectly, is going to report. Every other employee is going to have exactly one direct supervisor. As such a reform is bound to introduce friction between workers, your company's goal is to choose a hierarchy that minimizes social costs for the firm.

The amount of friction between two coworkers forced into a superior-subordinate relationship is proportional to the number of political issues they disagree on. In your company, every employee has very resolute views on each of the nn most common political topics: in each of the nn categories, an employee's opinions can be either leftist or rightist. To make matters worse, no two employees have identical beliefs. The cost of having one employee directly report to another is equal to the number of topics they disagree on. The cost of the new organizational structure is the sum of the costs of friction between every two employees such that one is (directly) managed by the other. You are asked to compute the minimum possible cost of the new structure.

입력

The first line of input contains the number of test cases zz (1≤z≤101 \leq z \leq 10). The descriptions of the test cases follow.

Every test case consists of two integers nn and mm (1≤n≤201 \leq n \leq 20, 1≤m≤2n1 \leq m \leq 2^n) -- the number of topics the workers have an opinion on and the number of employees, respectively. Next, mm lines follow, each describing the political opinions of one worker. The description of worker's views is a string consisting of nn letters. If the ii-th character is 'L' ('R'), the worker has leftist (rightist) views on the ii-th subject.

출력

For each test case output a line containing a single integer -- the minimum cost of the management hierarchy.

예제1

  1. 예제 1

    입력
    1
    5 4
    LLLLL
    LLLLR
    RRRRL
    RRRRR
    
    예상 출력
    6