import java.io.*; import java.util.*; /** * Score the runs and pairs just following the rules. To score the fifteens, * Generate all possible distinct partitions of 15 and use binomial coefficients * to efficiently count the number of ways to get cards whose values sum to 15. * * @author Finn Lidbetter */ public class cos_finn { static int MAX_N = 100; static long[][] combs = new long[MAX_N + 1][MAX_N + 1]; public static void main(String[] args) { Scanner sc = new Scanner(System.in); for (int i=0; i < MAX_N + 1; i++) { combs[i][0] = 1; combs[i][i] = 1; } for (int i=1; i < MAX_N + 1; i++) { for (int j=1; j0) { currRunLength += 1; } else if (cardCounts[i] == 0) { if (currRunLength >= 3) { long prod = 1; for (int j=currRunLength - 1; j>=0; j--) { prod *= (long)cardCounts[i-1-j]; } total += currRunLength * prod; } currRunLength = 0; } } if (currRunLength >= 3) { long prod = 1; for (int j=currRunLength - 1; j>=0; j--) { prod *= (long)cardCounts[cardCounts.length - 1 -j]; } total += currRunLength * prod; } return total; } static int[] nextPartition(int[] curr, int target) { if (curr.length == target) { return null; } for (int i=curr.length-2; i>=0; i--) { int total = 0; int[] candidate = new int[curr.length]; for (int j=0; j10) { valid = false; break; } multiplicities[i]++; if (multiplicities[i] > valueCounts[i]) { valid = false; break; } } if (valid) { long partitionTotal = 1; for (int value=1; value<=10; value++) { if (multiplicities[value] > 0) { partitionTotal *= combs[valueCounts[value]][multiplicities[value]]; } } total += partitionTotal; } currPartition = nextPartition(currPartition, 15); } return 2*total; } }