blob: 0b7889aa423f6c4166a5c5cfcd3256e47b2b7f39 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
program Ch2;
{$mode objfpc}
uses
SysUtils;
const
N:Integer = 5;
var
Count:Integer = 0;
Arr:array[0..4] of Integer;
procedure FindCombinations(var Arr:array of Integer;
Index,Num,ReducedNum:Integer);
var
I,Prev:Integer;
begin
if ReducedNum < 0 then Exit;
if ReducedNum = 0 then
begin
inc(Count);
Exit;
end;
if Index = 0 then Prev := 1 else Prev := Arr[Index-1];
for I := Prev to Num do
begin
Arr[Index] := I;
FindCombinations(Arr,Index+1,Num,ReducedNum-I);
end;
end;
begin
FindCombinations(Arr,0,N,N);
WriteLn(Count);
end.
|