fork(1) download
  1. public class ExactTree {
  2.  
  3. int calc(int n, int n1, int s1, int n2, int s2)
  4. {
  5. return s1 + s2 + n1 * (n - n1);
  6. }
  7.  
  8. public int getTree(int n, int m, int r)
  9. {
  10. int[][] dp = new int[n+1][m];
  11. for(int i = 1; i <= n; i++)
  12. for(int j = 0; j < m; j++)
  13. dp[i][j] = -1;
  14. dp[1][0] = 0;
  15. for(int s = 2; s <= n; s ++)
  16. for(int a = 1; a < s; a ++)
  17. for(int m1 = 0; m1 < m; m1 ++)
  18. for(int m2 = 0; m2 < m; m2 ++)
  19. {
  20. int b = s - a;
  21. if(dp[a][m1] == -1) continue;
  22. if(dp[b][m2] == -1) continue;
  23. int v = calc(n, a, dp[a][m1], b, dp[b][m2]);
  24. if(dp[s][v%m] == -1 || dp[s][v%m] > v)
  25. dp[s][v%m] = v;
  26. }
  27. return dp[n][r];
  28. }
  29. }
  30.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: class ExactTree is public, should be declared in a file named ExactTree.java
public class ExactTree {
       ^
1 error
stdout
Standard output is empty