RE*ALL求助

P1464 Function

HappyDavid @ 2023-07-16 14:43:50

#include <bits/stdc++.h>
using namespace std;
long long w_res[21][21][21], x, y, z, i, j, k;
#define w_res_init_num -9223372036854775808
long long w(long long a, long long b, long long c) {
    printf ("[wsDbg][Line5][clock%d] a=%lld,b=%lld,c=%lld,w_res[a][b][c]=%lld\n", clock(),a,b,c,w_res[a][b][c]);
    if (w_res[a][b][c] != w_res_init_num) return w_res[a][b][c];
    if (a < 0 || b < 0 || c < 0) return w (0, 0, 0); if (a > 20 || b > 20 || c > 20) return w (20, 20, 20);
    if (a < b && b < c) w_res[a][b][c] = w (a, b, c - 1) + w (a, b - 1, c - 1) - w (a, b - 1, c);
    else w_res[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 w_res[a][b][c];
}
int main() {
    for (i = 0; i < 21; i++) for (j = 0; j < 21; j++) for (k = 0; k < 21; k++) w_res[i][j][k] = w_res_init_num;
    // memset (w_res, -9223372036854775808, sizeof (w_res)); w_res[0][0][0] = 1;
    while (true) {
        scanf ("%lld%lld%lld", &x, &y, &z);
        if (x == -1 && y == -1 && z == -1) break;
        else printf ("w(%lld, %lld, %lld) = %lld\n", x, y, z, w (x, y, z));
    }
    return 0;
}

谢谢辣~!(请先看一看评论,或许我自己解决了呢?)

悬赏一个关注 ,然后在我弟弟面前装个B

验证码RETN祭


by HappyDavid @ 2023-07-16 14:45:59

@HappyDavid 调试信息不用管!


by HappyDavid @ 2023-07-16 14:59:44

wssb,<0判断应该在记忆化判断前面,但是死循环了?


by HappyDavid @ 2023-07-16 15:02:37

@HappyDavid 还有>20判断,但是这似乎并不影响死循环……


by HappyDavid @ 2023-07-16 15:23:40

好了,if (a < 0 || b < 0 || c < 0) return w (0, 0, 0);应该改成if (a <= 0 || b <= 0 || c <= 0) return 1;。


by sssscy_free_stdio @ 2023-07-16 15:26:37

<=0?


by sssscy_free_stdio @ 2023-07-16 15:27:42

试一下,我代码写的是<=0,过了


by HappyDavid @ 2023-07-16 15:29:29

还是RE*ALL……

记录

代码:

#include <bits/stdc++.h>
using namespace std;
long long w_res[21][21][21], x, y, z, i, j, k;
#define w_res_init_num -9223372036854775808
long long w(long long a, long long b, long long c) {
    printf ("[wsDbg][Line5][clock%d] a=%lld,b=%lld,c=%lld,w_res[a][b][c]=%lld\n", clock(),a,b,c,w_res[a][b][c]);
    if (a <= 0 || b <= 0 || c <= 0) return 1;
    if (a > 20 || b > 20 || c > 20) return w (20, 20, 20);
    if (w_res[a][b][c] != w_res_init_num) return w_res[a][b][c];
    if (a < b && b < c) w_res[a][b][c] = w (a, b, c - 1) + w (a, b - 1, c - 1) - w (a, b - 1, c);
    else w_res[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 w_res[a][b][c];
}
int main() {
    for (i = 0; i < 21; i++) for (j = 0; j < 21; j++) for (k = 0; k < 21; k++) w_res[i][j][k] = w_res_init_num;
    while (true) {
        scanf ("%lld%lld%lld", &x, &y, &z);
        if (x == -1 && y == -1 && z == -1) break;
        else printf ("w(%lld, %lld, %lld) = %lld\n", x, y, z, w (x, y, z));
    }
    return 0;
}

by sssscy_free_stdio @ 2023-07-16 15:33:31

不用把w_res数组全部写成-9223372036854775808,直接写成0,判断的时候判断w_res[a][b][c] >0就行了,而且RE的话数组开大点?开到30试试


by sssscy_free_stdio @ 2023-07-16 15:35:47

不一定对(我是个大蒟蒻)


by sssscy_free_stdio @ 2023-07-16 15:37:07

对吗?


| 下一页