yjjh @ 2024-07-03 10:33:20
#include <bits/stdc++.h>
using namespace std;
long long ww[300][300][300];//这里是记忆化数组(250 A一个 300 MLE了 awa)
inline long long w(long long a,long long b,long long c){
if(ww[a][b][c]!=-1)return ww[a][b][c];
if(a<=0||b<=0||c<=0){
ww[a][b][c]=1;
return 1;
}
if(a>20||b>20||c>20){
long long t=w(20,20,20);
ww[a][b][c]=t;
return t;
}
if(a<b&&b<c){
long long t=w(a,b,c-1)+w(a,b-1,c-1)-w(a,b-1,c);
ww[a][b][c]=t;
return t;
}
long long t=w(a-1,b,c)+w(a-1,b-1,c)+w(a-1,b,c-1)-w(a-1,b-1,c-1);
ww[a][b][c]=t;
return t;
}
int main(){
memset(ww,-1,sizeof(ww));
long long a,b,c;
while(1){
std::cin >>a>>b>>c;
if(a==-1&&b==-1&&c==-1)return 0;
std::cout <<"w("<<a<<", "<<b<<", "<<c<<") = "<<w(a,b,c)<<std::endl;
}
}
by libohan356218 @ 2024-07-03 10:36:36
30就够了,你应该是别的错误
by chenjiayicxq821411 @ 2024-07-03 10:42:37
#include<bits/stdc++.h>
#define ll long long
using namespace std;
#define ll long long
int f[25][25][25];
int n;
ll a,b,c;
ll w(ll x,ll y,ll z)
{
if(x<=0||y<=0||z<=0) return 1;
if(x>20||y>20||z>20) return f[20][20][20]=w(20,20,20);
if(f[x][y][z]) return f[x][y][z];
if(x<y&&y<z) return f[x][y][z]=w(x,y,z-1)+w(x,y-1,z-1)-w(x,y-1,z);
else return f[x][y][z]=w(x-1,y,z)+w(x-1,y-1,z)+w(x-1,y,z-1)-w(x-1,y-1,z-1);
}
int main()
{
while(scanf("%lld%lld%lld",&a,&b,&c)!=EOF)
{
if(a==-1&&b==-1&&c==-1) return 0;
if(a<=0||b<=0||c<=0) printf("w(%lld, %lld, %lld) = 1\n",a,b,c);
else if(a>20||b>20||c>20) printf("w(%lld, %lld, %lld) = %lld\n",a,b,c,w(20,20,20));
else printf("w(%lld, %lld, %lld) = %lld\n",a,b,c,w(a,b,c));
}
}
by jzm_2024 @ 2024-07-03 10:43:29
开到四维试试
by fly_x @ 2024-07-04 12:51:50
@yjjh 不是数组的问题, 因为 a,b,c 可能为负 此时数组下标会越界
把这个 ↓
if(ww[a][b][c]!=-1)return ww[a][b][c];
移到特判后就好了
by yjjh @ 2024-07-04 20:50:37
@chenjiayicxq821411 感谢大佬,已AC,已关