Created
October 9, 2018 21:42
-
-
Save robmoore/a829b870f289845a70d157d9b7d0fa32 to your computer and use it in GitHub Desktop.
Can calculate count of odd integer partitions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PartitionCounter { | |
public static void main(String[] args) { | |
// System.out.print("["); | |
// for (int k = 0; k < 201; k++) { | |
// System.out.print(count(k) + (k != 200 ? ", " : "")); | |
// } | |
// System.out.print("]"); | |
System.out.println("11: " + count(11)); | |
} | |
private static int count(int x) { | |
if (x < 3) { | |
return 0; | |
} | |
int f[] = new int[x + 1]; | |
f[0] = 1; | |
f[1] = 1; | |
for (int n = 2; n <= x; n++) { | |
for (int k = x; k > n - 1; k--) { | |
f[k] += f[k - n]; | |
} | |
} | |
return f[x] - 1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment