comcnSBhhh @ 2024-07-04 16:03:26
#include<bits/stdc++.h>
using namespace std;
long long w(long long a,long long b,long long c)
{
if(a<=0||b<=0||c<=0)
{
return 1;
}
if(a>20||b>20||c>20)
{
return w(20,20,20);
}
if(a<b&&b<c)
{
return w(a,b,c-1)+w(a-1,b-1,c)+w(a-1,b,c-1)-w(a-1,b-1,c-1);
}
return (a-1,b,c)+w(a-1,b-1,c)+w(a-1,b,c-1)-w(a-1,b-1,c-1);
}
int main()
{
long long a,b,c;
while(cin>>a>>b>>c)
{
if(a==-1&&b==-1&&c==-1)
{
break;
}
cout<<"w("<<a<<", "<<b<<", "<<c<<") = "<<w(a,b,c)<<endl;
}
return 0;
}
样例可过求调QAQ
by 2022linzhiyi @ 2024-07-04 16:12:21
你不记搜当然TLE了。
by huangchengyu @ 2024-07-07 18:31:19
要记忆化搜索的,可以开个数组记一下