为啥compile error

P1464 Function

HYQ1234 @ 2023-02-11 15:34:22

各位大佬帮个忙看一下P1464为什么交上这个代码就Compile Error

#include<iostream>
using namespace std;
long long fun[1005][1005][1005] = {};
long long w(long long a,long long b,long long c){
    if(fun[a][b][c] == 0){
        if(a <= 0 || b <= 0 || c <= 0)
            fun[a][b][c] = 1;
        else if(a > 20 || b > 20 || c > 20)
            fun[a][b][c] = w(20,20,20);
        else if(a < b && b < c)
            fun[a][b][c] = w(a,b,c - 1);
        else
            fun[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 fun[a][b][c];
}
int main(){
    long long a = 0,b = 0,c = 0;
    while(cin >> a >> b >> c){
        if(a == -1 && b == -1 && c == -1)
            break;
        printf("w(%lld, %lld, %lld) = %llu\n",a,b,c,w(a,b,c));
    }
    return 0;
}

然后链接在这里 P1416 Function


by Acoipp @ 2023-02-11 15:38:12

数组开大了哦,尝试开小一点


by Hughpig @ 2023-02-11 15:39:50

@HYQ1234 你数组太大了。


by reveal @ 2023-02-11 15:40:43


by AstaSunch_ @ 2023-02-11 15:58:33

数组开到35^3就够了


by HYQ1234 @ 2023-02-11 19:24:03

缩小到35就全re 扩大到305只有一个ac


by HYQ1234 @ 2023-02-12 15:11:55

啊 已经懂了 数组只要设置到20 20 20就够了


by Chenyufeng040525 @ 2023-05-27 01:27:13

@HYQ1234 RE是因为数组越界了,小于0和大于20的情况直接返回1和w(20.20.20)就行了,不用给数组赋值


|