100分未过,求助!!

P1464 Function

@[Sky_lzr03](/user/747009) 开 `long long`
by Misophiliac @ 2023-07-13 09:47:33


@[yuanxiuan](/user/614716) 已A,Thanks♪(・ω・)ノ
by Spir1t @ 2023-07-13 12:34:28


代码君来啦||ヽ(* ̄▽ ̄*)ノミ|Ю ```cpp #include<bits/stdc++.h> using namespace std; int s[30][30][30]; long long f(long long a,long long b,long long c) { if(a<=0 || b<=0 || c<=0) return 1; else if(a>20 || b>20 || c>20) return f(20,20,20); else if(s[a][b][c]!=0) return s[a][b][c]; else if(a<b && b<c) { s[a][b][c]=f(a,b,c-1)+f(a,b-1,c-1)-f(a,b-1,c); return s[a][b][c]; } else { s[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); return s[a][b][c]; } } int main() { long long a,b,c; cin>>a>>b>>c; while(!(a==-1 && b==-1 && c==-1)) { cout<<"w("<<a<<", "<<b<<", "<<c<<") = "<<f(a,b,c)<<endl; cin>>a>>b>>c; } return 0; } ```
by max11 @ 2023-07-15 09:55:00


不用我这种方法肯定不对。 代码: ```c #include<bits/stdc++.h> using namespace std; long long s[21][21][21]; long long w(long long a,long long b,long long 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(s[a][b][c]!=0) return s[a][b][c]; else if(a<b && b<c) { s[a][b][c]=w(a,b,c-1)+w(a,b-1,c-1)-w(a,b-1,c); return s[a][b][c]; } else { s[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 s[a][b][c]; } } long long a,b,c; int main() { cin>>a>>b>>c; while(!(a==-1 && b==-1 && c==-1)) { cout<<"w("<<a<<", "<<b<<", "<<c<<") = "<<w(a,b,c)<<endl; cin>>a>>b>>c; } return 0; } ```
by joe_001 @ 2023-07-15 09:56:10


谢谢大佬们,已A了
by Spir1t @ 2023-07-15 12:39:53


|