|
| 1 | +package main.java.videos; |
| 2 | + |
| 3 | +import java.io.BufferedReader; |
| 4 | +import java.io.IOException; |
| 5 | +import java.io.InputStreamReader; |
| 6 | +import java.util.Arrays; |
| 7 | + |
| 8 | +public class TShirts { |
| 9 | + public static void main(String[] args) throws IOException { |
| 10 | + final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); |
| 11 | + final StringBuilder stringBuilder = new StringBuilder(); |
| 12 | + for (int t = Integer.parseInt(br.readLine()); t > 0; t--) { |
| 13 | + final int n = Integer.parseInt(br.readLine()); |
| 14 | + final int sets[] = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); |
| 15 | + stringBuilder.append(new Solver(sets).solve()).append('\n'); |
| 16 | + } |
| 17 | + System.out.println(stringBuilder); |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +class Solver { |
| 22 | + |
| 23 | + public static final int MOD = 1000000007; |
| 24 | + private int[][] shirtSets; |
| 25 | + |
| 26 | + public Solver(final int[] people) { |
| 27 | + final int shirtSets[][] = new int[100][people.length]; |
| 28 | + final int count[] = new int[people.length]; |
| 29 | + for (int i = 0; i < people.length; i++) { |
| 30 | + shirtSets[people[i]][count[people[i]]++] = i; |
| 31 | + } |
| 32 | + this.shirtSets = shirtSets; |
| 33 | + } |
| 34 | + |
| 35 | + public long solve() { |
| 36 | + return possiblities(0, 0); |
| 37 | + } |
| 38 | + |
| 39 | + private long possiblities(final int people, final int assigned) { |
| 40 | + long answer = 0; |
| 41 | + for (int i = 0; i < shirtSets[assigned].length; i++) { |
| 42 | + int person = shirtSets[assigned][i]; |
| 43 | + if ((people & (1 << person)) == 0) { |
| 44 | + int changedPeople = people; |
| 45 | + changedPeople = changedPeople | (1 << person); |
| 46 | + answer = (answer + possiblities(changedPeople, assigned + 1)) % MOD; |
| 47 | + } |
| 48 | + } |
| 49 | + return answer; |
| 50 | + } |
| 51 | +} |
0 commit comments