fork(3) download
  1. type
  2. TSol = array [1..100] of Integer;
  3.  
  4. var
  5. n, m : Integer;
  6. a : array [1..100] of Integer;
  7.  
  8. procedure Solution (cnt, sum : Integer; b : TSol);
  9. var
  10. i : Integer;
  11. begin
  12. if sum = n then begin
  13. for i := 1 to m do
  14. if b[i] <> 0 then
  15. Write (b[i], '+');
  16. WriteLn(#8, ' = ', n)
  17. end;
  18.  
  19.  
  20. if cnt > m then
  21. Exit;
  22.  
  23. for i := 1 to m do begin
  24. if (b[i] = a[i]) or (b[i] <> 0) then
  25. Continue;
  26.  
  27. b[i] := a[i];
  28. Solution (i, sum + a[i], b);
  29. b[i] := 0
  30. end;
  31.  
  32. end;
  33.  
  34. var
  35. b : TSol;
  36. i : Integer;
  37.  
  38. begin
  39. ReadLn (n, m);
  40.  
  41. for i := 1 to m do
  42. Read (a[i]);
  43.  
  44. for i := 1 to m do begin
  45. b[i] := a[i];
  46. Solution (i, a[i], b);
  47. b[i] := 0
  48. end
  49. end.
  50.  
Success #stdin #stdout 0s 276KB
stdin
3 3
1 1 1
stdout
1+1+1+ = 3
1+1+1+ = 3
1+1+1+ = 3
1+1+1+ = 3
1+1+1+ = 3
1+1+1+ = 3