100分未过,求助!!

P1464 Function

Spir1t @ 2023-07-13 09:36:21

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll read() {
    ll x = 0, f = 1;
    char ch = getchar();
    while (ch > '9' || ch < '0') {
        if (ch == '-')f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}
int dp[30][30][30];
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 w(20, 20, 20);
    } else if (dp[a][b][c]) {
        return dp[a][b][c];
    } else if (a < b && b < c) {
        dp[a][b][c] = w(a, b, c - 1) + w(a, b - 1, c - 1) - w(a, b - 1, c);
    } else {
        dp[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 dp[a][b][c];
}
signed main() {
    int a, b, c;
    while (cin >> a >> b >> c) {
        if (a == -1 && b == -1 && c == -1) {
            break;
        }
        int ans = w(a, b, c);
        cout << "w(" << a << ", " << b << ", " << c << ") = " << ans << endl;
    }
    return 0;
}

by Misophiliac @ 2023-07-13 09:47:33

@Sky_lzr03 开 long long


by Spir1t @ 2023-07-13 12:34:28

@yuanxiuan

已A,Thanks♪(・ω・)ノ


by max11 @ 2023-07-15 09:55:00

代码君来啦||ヽ( ̄▽ ̄)ノミ|Ю

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

by joe_001 @ 2023-07-15 09:56:10

不用我这种方法肯定不对。 代码:

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

by Spir1t @ 2023-07-15 12:39:53

谢谢大佬们,已A了


|