<分区>
程序要写,N的自然被加数有多少种不同的组合。所有的被加数不大于,则K(N,K<=120)。 我的程序只包含递归:
int F (int x,int s) // s- total number, which is necessary to lay down the terms of
{
if (s == 0) // when total number == 0
{
ans++;
return 0;
}
for (int i=x;i<=min(k,s);i++) // x - previous term
F(i,s-i); // we add a new summand -> subtract that number from the amount
}
主要部分:
int main ()
{
cin >> n>> k;
F(1,n);
cout << ans;
}
那么,你能帮我更快地完成我的程序吗?