empty_winner @ 2024-12-22 16:11:06
#include <iostream>
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) f[a][b][c]=w(a,b,c-1)+w(a,b-1,c-1)-w(a,b-1,c);
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);
return f[a][b][c];
}
int main()
{
long long a,b,c;
while(cin>>a>>b>>c)
{
if(a==-1&&b==-1&&c==-1)return 0;
cout<<"w("<<a<<", "<<b<<", "<<c<<") = "<<w(a,b,c)<<endl;
}
return 0;
}
在自定义函数中没有用else但答案正确,有人能解释一下码
by LionBlaze @ 2024-12-22 16:38:11
@empty_winner 我也不知道为啥,可是答案就是对的。
by empty_winner @ 2024-12-22 16:38:50
@LionBlaze 所以第9,10行代码等价?
by LionBlaze @ 2024-12-22 16:39:53
@empty_winner 是的。
by LionBlaze @ 2024-12-22 16:40:04
真有趣
by empty_winner @ 2024-12-22 16:45:00
@LionBlaze 666,我看看能不能证明一下
by empty_winner @ 2024-12-22 17:18:46
@Empty_Dream
by Empty_Dream @ 2024-12-22 17:24:04
@empty_winner 领导,我们名字好像啊
by empty_winner @ 2024-12-23 12:10:40
@Empty_Dream 所以呢,题面有问题吗