public int numberOfSubsets(int goodValue, int[] d) { HashMap<Integer, Integer> map = new HashMap<>(); // prod, sets for (int i = 0; i < d.length; i++) { HashMap<Integer, Integer> nmap = new HashMap<>(); nmap.put(d[i], 1); for (Map.Entry<Integer, Integer> entry : map.entrySet()) { // not use Integer setcount = nmap.get(entry.getKey()); if (setcount == null) setcount = 0; setcount = (entry.getValue() + setcount) % MOD; nmap.put(entry.getKey(), setcount); // use int nprod = entry.getKey(); if (nprod > goodValue / d[i]) continue; nprod *= d[i]; if (goodValue % nprod != 0) continue; setcount = nmap.get(nprod); if (setcount == null) setcount = 0; setcount = (entry.getValue() + setcount) % MOD; nmap.put(nprod, setcount); } map = nmap; } return map.get(goodValue) == null ? 0 : map.get(goodValue); }
public static void main(String[] args) { long start = System.currentTimeMillis(); Scanner input = new Scanner(System.in); int numberOfTestCases = input.nextInt(); ArrayList<Integer> order = new ArrayList<Integer>(numberOfTestCases); int previousKey = -1; int previousValue = 0; int cycleNumber = 0; Map<Integer, Integer> testCases = new TreeMap<Integer, Integer>(); for (int i = 0; i < numberOfTestCases; i++) { int numberOfCycles = input.nextInt(); testCases.put(numberOfCycles, 1); order.add(numberOfCycles); } for (Map.Entry<Integer, Integer> entry : testCases.entrySet()) { int numberOfCycles; int initialHeight; if (previousKey == -1) { numberOfCycles = entry.getKey(); initialHeight = entry.getValue(); } else { numberOfCycles = entry.getKey() - previousKey; initialHeight = previousValue; } for (int i = 0; i < numberOfCycles; i++) { if (cycleNumber % 2 == 0) { initialHeight *= 2; } else { initialHeight += 1; } cycleNumber++; } entry.setValue(initialHeight); previousKey = entry.getKey(); previousValue = initialHeight; } for (Integer element : order) { System.out.println(testCases.get(element)); } long elapsed = System.currentTimeMillis() - start; System.out.println("time: " + elapsed); }
// this method basically will chop up the blocks and get their frequencies private static void getBlockFrequency() throws Exception { directory = "../../thesis-datasets/morph_file_100MB/"; ReadFile.readFile(directory, fileList); // read the two files HashMap<Integer, Integer> blockFreq = new HashMap<Integer, Integer>(); // this stores the block in the map along there frequencies int start = 0; // start of the sliding window int end = start + window - 1; // ending boundary preliminaryStep(directory); // System.out.println("Choping the document TDDD " + fileList.get(0)); long[] divisorArray = { 1000 }; // run the frequency code for these divisor values (AKA expected block Size) for (long i : divisorArray) { long divisor1 = i; long divisor2 = i / 2; long divisor3 = i / 4; long remainder = 7; long minBoundary = min_multiplier * i; long maxBoundary = max_multiplier * i; // System.out.println("Running Likelihood for " + i + " " + divisor2 + " " + divisor3); int totalBlocks = chopDocument( fileArray.get(0), hashed_File_List.get(0), divisor1, divisor2, divisor3, remainder, minBoundary, maxBoundary, blockFreq); // now output the block sizes, along with there frequencies and probilities for (Map.Entry<Integer, Integer> tuple : blockFreq.entrySet()) { // output the block freq double prob = (double) tuple.getValue() / (double) totalBlocks; System.out.println(tuple.getKey() + " " + tuple.getValue() + " " + prob); } blockFreq.clear(); } }