全STL了,大佬围观一下我这个菜鸡怎么错了

P1464 Function

devcjj @ 2023-02-03 17:38:20

#include<iostream>
#include<cmath>
#define N 30;
using namespace std;
long long shu[30][30][30];
int dfs(int  a,int b, int c)
{
    if (shu[a][b][c] != 0)
    {
        return shu[a][b][c];
    }
    else if (a <= 0 || b <= 0 || c <= 0)
    {

        return 1;
    }
    else if (a > 20 || b > 20 || c > 20)
    {
        shu[a][b][c] = dfs(20, 20, 20);
        return shu[a][b][c];

    }
    else if (a < b && b < c)
    {
        shu[a][b][c] = dfs(a, b, c - 1) + dfs(a, b - 1, c - 1) + dfs(a, b - 1, c - 1);
        return shu[a][b][c];
    }
    else {
        shu[a][b][c] = dfs(a - 1, b, c) + dfs(a - 1, b - 1, c) + dfs(a - 1, b, c - 1) + dfs(a - 1, b - 1, c - 1);
        return shu[a][b][c];
    }
}
int main()
{
    std::ios::sync_with_stdio(false);
    long long a = 0, b = 0, c = 0;
    while (a != -1 && b != -1 && c != -1)
    {
        cin >> a >> b >> c;
        if (a <= 0 || b <= 0 || c <= 0)
        {
            cout << "w(" << a << "," << b << "," << c << ")=" << "1" << endl;
        }
        else
        {
            if (a > 20 || b > 20 || c > 20)
            {
                dfs(20, 20, 20);
                cout << "w(" << a << ", " << b << ", " << c << ") = " << shu[20][20][20] << endl;
            }
            else {
                dfs(a, b, c);
                cout << "w(" << a << ", " << b << ", " << c << ") = " << shu[a][b][c] << endl;
            }
        }
        a = 0, b = 0, c = 0;
    }
}

by User_Unauthorized @ 2023-02-03 17:40:00

猜您想说:全 TLE


by heike305 @ 2023-02-03 17:54:03

@devcjj

要记忆化


by devcjj @ 2023-02-03 19:18:42

@heike305 我用了记忆化了呀


by heike305 @ 2023-02-03 20:04:51

@devcjj 用的C?


by devcjj @ 2023-02-03 20:05:46

@heike305 C++


by heike305 @ 2023-02-03 20:20:36

@devcjj

这个程序一直在输入,建议把

    while (a != -1 && b != -1 && c != -1)
    {
        cin >> a >> b >> c;
        if (a <= 0 || b <= 0 || c <= 0)
        {
            cout << "w(" << a << "," << b << "," << c << ")=" << "1" << endl;
        }
        else
        {
            if (a > 20 || b > 20 || c > 20)
            {
                dfs(20, 20, 20);
                cout << "w(" << a << ", " << b << ", " << c << ") = " << shu[20][20][20] << endl;
            }
            else {
                dfs(a, b, c);
                cout << "w(" << a << ", " << b << ", " << c << ") = " << shu[a][b][c] << endl;
            }
        }
        a = 0, b = 0, c = 0;
    }

换成

    while (1)
    {
        cin >> a >> b >> c;
        if(a < 0 && b < 0 && c < 0)
        {
            break;
        } 
        if (a <= 0 || b <= 0 || c <= 0)
        {
            cout << "w(" << a << "," << b << "," << c << ")=" << "1" << endl;
        }
        else
        {
            if (a > 20 || b > 20 || c > 20)
            {
                dfs(20, 20, 20);
                cout << "w(" << a << ", " << b << ", " << c << ") = " << shu[20][20][20] << endl;
            }
            else {
                dfs(a, b, c);
                cout << "w(" << a << ", " << b << ", " << c << ") = " << shu[a][b][c] << endl;
            }
        }
    }

还有,你这个程序没过样例,建议先自己测过样例还过不了才发帖求助。


by devcjj @ 2023-02-03 21:16:38

@heike305 我天!没过样例,真不好意思,我改了代码,忘了检查样例了,谢谢您


by DBL_MAX @ 2023-06-03 20:01:05

额。。。


|