Charlie509 @ 2024-06-16 11:59:11
#include<bits/stdc++.h>
using namespace std;
long long w(int a,int b,int c){
if(a<=0||b<=0||c<=0)return 1;
else if(a>20||b>20||c>20)return w(20,20,20);
else if(a<b&&b<c)return w(a,b,c-1)+w(a,b-1,c-1)-w(a,b-1,c);
else return w(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()
{
int 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)<<"\n";
}
return 0;
}
求助,样例过了!
by zhouzihang1 @ 2024-06-16 12:14:01
@Charlie509 会爆栈或超时,需要记忆化