全WA求助 样例可以过

P1464 Function

hutaooooooo @ 2023-08-19 16:11:25

#include<bits/stdc++.h>
using namespace std ;
typedef long long op ;
const op N = 22 ;
op sum = 0 , n ;
op ht[ N ][ N ][ N ] ;
op ggbond( op a , op b , op c )
{
    if( a <= 0 || b <= 0 || c <= 0 ) return 1 ;
    else if( a > 20 || b > 20 || c > 20 ) return ggbond( 20 , 20 , 20 ) ;
    else if( a < b && b < c ) 
    {
        if( !ht[ a ][ b ][ c - 1 ] ) ht[ a ][ b ][ c - 1 ] = ggbond( a , b , c - 1 ) ;
        if( !ht[ a ][ b - 1 ][ c ] ) ht[ a ][ b - 1 ][ c ] = ggbond( a , b - 1 , c ) ;
        if( !ht[ a ][ b ][ c - 1 ] ) ht[ a ][ b - 1 ][ c - 1 ] = ggbond( a , b - 1 , c - 1 ) ;
        return ht[ a ][ b ][ c ] = ht[ a ][ b ][ c - 1 ] + ht[ a ][ b - 1 ][ c ] - ht[ a ][ b - 1 ][ c - 1 ] ;
    }
    else
    {
        if( !ht[ a - 1 ][ b ][ c ] ) ht[ a - 1 ][ b ][ c ] = ggbond( a - 1 , b , c ) ;
        if( !ht[ a - 1 ][ b - 1 ][ c ] ) ht[ a - 1 ][ b - 1 ][ c ] = ggbond( a - 1 , b - 1 , c ) ;
        if( !ht[ a - 1 ][ b ][ c - 1 ] ) ht[ a - 1 ][ b ][ c - 1 ] = ggbond( a - 1 , b , c - 1 ) ;
        if( !ht[ a - 1 ][ b - 1 ][ c - 1 ] ) ht[ a - 1 ][ b - 1 ][ c - 1 ] = ggbond( a - 1 , b - 1 , c - 1 ) ;
        return ht[ a ][ b ][ c ] = ht[ a - 1 ][ b ][ c ] + ht[ a - 1 ][ b - 1 ][ c ] + ht[ a - 1 ][ b ][ c - 1 ] - ht[ a - 1][ b - 1 ][ c - 1 ] ;
    }
}
int main( )
{
    op a , b , c ;
    while( cin >> a >> b >> c )
        if( a == -1 && b == -1 && c == -1 ) 
            break ;
        else 
            cout << "w(" << a << ", " << b << ", " << c << ") = " << ggbond( a , b , c ) << endl ;
}

by drinktowind @ 2023-08-19 16:20:25

#include <bits/stdc++.h>
using namespace std;
int a[30][30][30];
long long f(long long x,long long y,long long z)
{
    if(x<=0||y<=0||z<=0)
        return 1;
    if(x>20||y>20||z>20)
    {
        a[20][20][20]=f(20,20,20);
        return a[20][20][20];
    }
    if(a[x][y][z])
        return a[x][y][z];
    if(x<y&&y<z)
        a[x][y][z]=f(x,y,z-1)+f(x,y-1,z-1)-f(x,y-1,z);
    else
        a[x][y][z]=f(x-1,y,z)+f(x-1,y-1,z)+f(x-1,y,z-1)-f(x-1,y-1,z-1);
    return a[x][y][z];
}
int main()
{
    long long n,x,y;
    while(cin>>n>>x>>y)
    {
        if(n==-1&&x==y&&n==x)
            return 0;
        printf("w(%lld, %lld, %lld) = %lld\n",n,x,y,f(n,x,y));
    }
    return 0;
}

看看我的吧十分简便


by drinktowind @ 2023-08-19 16:21:29

我是如果有值直接返回,这样就不用一大堆判断


by drinktowind @ 2023-08-19 16:21:52

如果有用关注一下谢谢喵


by hutaooooooo @ 2023-08-20 09:46:27

AC了谢谢大佬

%%%%%%

已关注


|