求调,玄关

P1464 Function

Crow_ming @ 2024-08-14 22:18:45

MLE5+WA2

(小脑萎缩)

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a,b,c,ansed[21][21][21];
ll w(ll a,ll b,ll c) {
    if(a<=0||b<=0||c<=0) return 1;//情况一
    if(a>20) a=20;
    if(b>20) b=20;
    if(c>20) c=20;
    if(ansed[a][b][c]!=0) {
        return ansed[a][b][c];
    }
    if(a==20&&b==20&&c==20) { //情况二
        ll tmp=w(20,20,20);
        ansed[20][20][20]=tmp;
        return tmp;
    }

    if(a<b&&b<c) { //情况3
        ll tmp=w(a,b,c-1)+w(a,b-1,c-1)-w(a,b-1,c);
        ansed[a][b][c]=tmp;
        return tmp;
    }
    ll tmp=w(a-1,b,c)+w(a-1,b-1,c)+w(a-1,b,c-1)-w(a-1,b-1,c-1);
    ansed[a][b][c]=tmp;
    return tmp;

}
int main() {
    cin>>a>>b>>c;
    while(a!=-1&&b!=-1&&c!=-1) {
        ll ans=w(a,b,c);
        printf("w(%lld, %lld, %lld) = %lld\n",a,b,c,ans);
        cin>>a>>b>>c;
    }
    return 0;
}

by Huoxiangji @ 2024-08-18 23:16:26

改了多少我也不知道了,建议自己对照,就我这一脚猫的功夫……

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a,b,c,ansed[21][21][21];
ll w(ll a,ll b,ll c) {
    if(a<=0||b<=0||c<=0) return 1;
    if(a>20||b>20||c>20){
        a=20;b=20;c=20;
    }
    if(ansed[a][b][c]!=-1) {
        return ansed[a][b][c];
    }
    if(a<b&&b<c) {
        ansed[a][b][c]=w(a,b,c-1)+w(a,b-1,c-1)-w(a,b-1,c);
        return ansed[a][b][c];
    }
    ansed[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 ansed[a][b][c];

}
int main() {
    cin>>a>>b>>c;
    memset(ansed,-1,sizeof(ansed));
    while(a!=-1||b!=-1||c!=-1) {
        ll ans=w(a,b,c);
        printf("w(%lld, %lld, %lld) = %lld\n",a,b,c,ans);
        cin>>a>>b>>c;
    }
    return 0;
}

我还把代码改的偏向自己风格了一点


|