fork(1) download
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.  
  5. int c[] = new int[11];
  6. void f(int n, int s, int[] cc) {
  7. for (int i = 1; i <= c[n]; ++i) {
  8. cc[n] += i;
  9. s += i * n;
  10. if (s == 10) {
  11. for (int z = 0; z <= c[0]; ++z) {
  12. for (int j = 0; j < z; ++j) {
  13. System.out.print("0 ");
  14. }
  15. for (int j = 1; j <= 10; ++j) {
  16. for (int k = 0; k < cc[j]; ++k) {
  17. System.out.print(j + " ");
  18. }
  19. }
  20. System.out.println("");
  21. }
  22. }
  23. if (s >= 10) {
  24. cc[n] -= i;
  25. return;
  26. }
  27. for (int m = n + 1; m <= 10; ++m) {
  28. f(m, s, cc);
  29. }
  30. s -= i * n;
  31. cc[n] -= i;
  32. }
  33. }
  34.  
  35. void g() {
  36. Scanner scanner = new Scanner(System.in);
  37. while (scanner.hasNext()) {
  38. int x = scanner.nextInt();
  39. if (x >= 0 && x <= 10) {
  40. c[x]++;
  41. }
  42. if (x == -1) {
  43. break;
  44. }
  45. }
  46. int[] cc = new int[11];
  47. for (int i = 1; i <= 10; ++i) {
  48. f(i, 0, cc);
  49. }
  50. }
  51.  
  52. public static void main(String[] args) {
  53.  
  54. Main x = new Main();
  55. x.g();
  56. }
  57. }
  58.  
Success #stdin #stdout 0.06s 711680KB
stdin
2 2 3 5 0
stdout
2 3 5 
0 2 3 5