当前位置:网站首页>recursive recursive function

recursive recursive function

2022-08-10 13:21:00 51CTO


Approximate title:


Write a recursive function that evaluates as required by the title.


Thoughts:


Write the function according to the requirements of the title, just need to add a memory search.


Thinking:


When there are many recursive questions, you can use memory search.


Code:

#include

using namespace std;
int z[30][30][30]={0};
int f(int a,int b,int c)
{if(a<=0||b<=0||c<=0)return 1;
if(a>20||b>20||c>20)return f(20,20,20);
if(z[a][b][c]!=0)return z[a][b][c];
if(aelse return z[a][b][c]=(f(a-1,b,c)+f(a-1,b-1,c)+f(a-1,b,c-1)-f(a-1,b-1,c-1));


}

int main()
{
int a,b,c;
while(cin>>a>>b>>c)
{
cout<}
return 0;
}

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.

原网站

版权声明
本文为[51CTO]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/222/202208101233203440.html