千红万紫总是错!

P1464 Function

UKError @ 2023-05-10 22:18:23

本蒟蒻的代码

听取RE声一片

#include<bits/stdc++.h>
using namespace std;
int f[20][20][20];

int 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);
        return f[a][b][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) break;
        cout<<"w("<<a<<", "<<b<<", "<<c<<") = ";
        cout<<w(a,b,c)<<endl;
    }
    return 0;
}

本地运行没问题,到洛谷就RE了

为神马啊(QAQ)


by Terrible @ 2023-05-10 22:25:37

@UKError 什么都错只会害了你!

数组越界了,开到 [21][21][21]


by UKError @ 2023-05-10 22:30:12

.

.

.

.

.

.

6


by UKError @ 2023-05-10 22:30:36

此贴终结


by ABCgfed @ 2023-05-11 22:10:48

6


by Joe666 @ 2023-05-21 13:38:57

6


|