liangcha_crush_ly @ 2024-08-29 14:48:22
#include<iostream>
#define int long long
using namespace std;
int w[200][200][200],a,b,c;
int f(int a,int b,int c){
if(w[a][b][c])return w[a][b][c];
else if(a<=0||b<=0||c<=0)return 1;
else if(a>20||b>20||c>20)return f(20,20,20);
else if(a<b&&b<c)return w[a][b][c]=f(a,b,c-1)+f(a,b-1,c-1)-f(a,b-1,c);
else return w[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);
}
signed main(){
for(int i=1;;i++){
cin>>a>>b>>c;
if(a==-1&&b==-1&&c==-1)return 0;
cout<<"w("<<a<<" ,"<<b<<" ,"<<c<<") = "<<f(a,b,c)<<endl;
}
return 0;
}
by _Maverick_ @ 2024-08-29 14:54:12
#include<bits/stdc++.h>
using namespace std;
long long f[25][25][25];
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(f[a][b][c]!=0)return f[a][b][c];
if(a<b&&b<c)
return f[a][b][c]=w(a,b,c-1)+w(a,b-1,c-1)-w(a,b-1,c);
else{
return f[a][b][c]=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(){
long long a,b,c;
for(int i=1;;i++){
cin>>a>>b>>c;
if(a==-1&&b==-1&&c==-1){break;}
cout<<"w("<<a<<", "<<b<<", "<<c<<")"<<" = "<<w(a,b,c)<<endl;
}
return 0;
}
@liangcha_crush