求调

P1464 Function

_Cyan_Lemon_ @ 2024-07-22 15:45:08

#include<bits/stdc++.h>
#define int long long
using namespace std;

const int N=25;
int a,b,c;
int f[25][25][25];

int w(int a,int b,int c)
{
    if(a<=0||b<=0||c<=0)    { return 1; }
    else if(a>20||b>20||c>20)
    {
        return f[20][20][20];
    }
    else  if(f[a][b][c])    return f[a][b][c];
    else if(a<b&&b<c)
    {
        return w(a,b,c-1)+w(a,b-1,c-1)-w(a,b-1,c);
    }
    else
    {
        return  w(a-1,b,c)+w(a-1,b-1,c)+w(a-1,b,c-1)-w(a-1,b-1,c-1);
    }
}

signed main()
{
    for(int i=0;i<25;++i)
        for(int j=0;j<25;++j)
            for(int k=0;k<25;++k)
                f[i][j][k]=w(i,j,k);
    cin>>a>>b>>c;
    int d=0,e=0,f=0,g=0,k;
    while(a!=-1&&b!=-1&&c!=-1)
    {
        if(a==d&&b==e&&c==f)
        {
            k=g;
            printf("w(%lld, %lld, %lld) = %lld\n",a,b,c,g);
        }
        else
        {
            k=w(a,b,c);
            printf("w(%lld, %lld, %lld) = %lld\n",a,b,c,k);
        }
        d=a;e=b;f=c;g=k;
        cin>>a>>b>>c;
    }
    return 0;
}

by _liujunming_ @ 2024-07-25 14:49:47

#include<bits/stdc++.h>
using namespace std;
long long w[100][100][100];
long long s(long long a,long long b,long long c)
{
    if(a<=0||b<=0||c<=0)
    {
        return 1;
    }   
    else if(a>20||b>20||c>20)
    {
        return s(20,20,20);
    }
    if(w[a][b][c]!=0)return w[a][b][c];
    else if(a<b&&b<c)
    {
        w[a][b][c]=s(a,b,c-1)+s(a,b-1,c-1)-s(a,b-1,c);
        return w[a][b][c];      
    }
    else
    {
        w[a][b][c]=s(a-1,b,c)+s(a-1,b-1,c)+s(a-1,b,c-1)-s(a-1,b-1,c-1);
        return w[a][b][c];      
    }
}
int main()
{
    memset(w,0,sizeof(w));
    for(int i=1;;i++)
    {
        long long a,b,c;
        cin>>a>>b>>c;
        if(a==-1&&b==-1&&c==-1)return 0;
        printf("w(%lld, %lld, %lld) = %lld\n",a,b,c,s(a,b,c));
    }
    return 0;
}

|