WA on #3,7

P1464 Function

hiebb @ 2024-08-13 20:37:06

废话不多说,代码如下:

#include<bits/stdc++.h>
using namespace std;
int s[25][25][25];
int w(long long a,long long b,long long c){
    if(a>20||b>20||c>20) a=20,b=20,c=20;
    else if(a<1||b<1||c<1) return 1;
    if(s[a][b][c]);
    else if(a<b&&b<c) s[a][b][c]=w(a,b,c-1)+w(a,b-1,c-1)-w(a,b-1,c);
    else s[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 s[a][b][c];
}
int main(){
    long long a,b,c;
    while(1){
        cin>>a>>b>>c;
        if(a==-1&&b==-1&&c==-1) return 0;
        printf("w(%lld, %lld, %lld) = %d\n",a,b,c,w(a,b,c));
    }
}

by GrainRain25 @ 2024-08-13 20:50:39

#include<bits/stdc++.h>
using namespace std;
long long s[25][25][25];
long long w(long long a,long long b,long long c){
    if(a<1||b<1||c<1) return 1;
    else if(a>20||b>20||c>20) a=20,b=20,c=20;
    if(s[a][b][c])return s[a][b][c];
    else if(a<b&&b<c) s[a][b][c]=w(a,b,c-1)+w(a,b-1,c-1)-w(a,b-1,c);
    else s[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 s[a][b][c];
}
int main(){
    long long a,b,c;
    while(1){
        cin>>a>>b>>c;
        if(a==-1&&b==-1&&c==-1) return 0;
        printf("w(%lld, %lld, %lld) = %lld\n",a,b,c,w(a,b,c));
    }
}

第五行和第六行顺序反了,还有long long开到底


by hiebb @ 2024-08-13 21:03:18

感谢巨佬,已关


by hiebb @ 2024-08-13 21:05:32

但不开long long好像也能过


by johnhby @ 2024-08-14 14:30:36

不开long long的后果: ![出错](C:\Users\zhhsh\Pictures\Screenshots\屏幕截图 2024-08-14 142940.png)


by johnhby @ 2024-08-14 14:32:09

Subtask #0 0ms/0B RE #3 0ms/0B RE #4 0ms/0B RE #5 0ms/0B RE #6 0ms/0B RE #7 Subtask #1 3ms/560.00KB WA #1 33ms/680.00KB WA #2


|