不是VIP会员,不能显示答案

题目解答

题目:
var
n, m: integer;
function fun(n, minNum, maxNum: integer): integer;
var tot, i: integer;
begin
if n = 0 then
exit(1);
tot := 0;
for i := minNum to maxNum do
tot := tot + fun(n - 1, i + 1, maxNum);
exit(tot);
end;

begin
readln(n, m);
writeln(fun(m, 1, n));
end.
输入:6 3
输出:20
考点: 0
分析:
解答:
f(3,1,6)=f(2,2,6)+f(2,3,6)+f(2,4,6)+f(2,5,6)+f(2,6,6)+f(2,7,6)

f(2,7,6)=f(2,6,6)=0
f(2,5,6)=f(1,6,6)=f(0,7,6)=1;
f(2,4,6)=f(1,5,6)+f(1,6,6)=f(0,6,6)+f(0,7,6)+f(1,6,6)=3

f(2,3,6)=f(1,4,6)+f(1,5,6)+f(1,6,6)
f(1,4,6)=f(0,5,6)+f(0,6,6)+f(0,7,6)=3
f(1,5,6)=f(0,6,6)+f(0,7,6)=2
f(2,3,6)=3+2+1=6

f(2,2,6)=f(1,3,6)+f(1,4,6)+f(1,5,6)+f(1,6,6)+f(1,7,6)
f(1,3,6)=f(0,4,6)+f(0,5,6)+f(0,6,6)+f(0,7,6)=4
f(2,2,6)=4+3+2+1=10

总和为10+6+3+1=20
评论:
老师: 0