P1464

P1464 Function

M_Train @ 2023-12-17 15:53:04

怎么做啊??? 全错!!! 这是书上的答案

求大佬!


by M_Train @ 2023-12-17 15:54:01

题目:P1464 Function


by xiaoshumiao @ 2023-12-17 16:04:53

@M_Train 放个代码?


by M_Train @ 2023-12-17 19:29:34

发不了!!!


by M_Train @ 2023-12-17 19:34:32

#include<iostream>
using namespace std;
long long f[25][25][25];
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(f[a][b][c]!=0) return f[a][b][c];
    else if(a<b&&b<c)
        f[a][b][c]=w(a,b,c-1)+w(a,b-1,c-1)+w(a,b-1,c);
    else 
        f[a][b][c]=w(a-1,b,c)+w(a-1,b-1,c)+w(a,b,c-1)+w(a-1,b-1,c-1);
    return f[a][b][c];
}
int main()
{
    long long a,b,c;
    while (cin>>a>>b>>c){
        if(a==-1&&b==-1&&c==-1)
            break;
        cout<<"w("<< a<< ", "<<b<<", "<<c<<") = ";
        cout<<w(a,b,c)<<endl;
    }
    return 0;
}

by M_Train @ 2023-12-17 19:35:21

@xiaoshumiao

好了!


by xiaoshumiao @ 2023-12-17 20:08:31

@M_Train 仔细读题。递归调用时有一些减号你打成了加号。


by M_Train @ 2023-12-17 21:04:14

#include<iostream>
using namespace std;
long long f[25][25][25];
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(f[a][b][c]!=0) return f[a][b][c];
    else if(a<b&&b<c)
        f[a][b][c]=w(a,b,c-1)+w(a,b-1,c-1)+w(a,b-1,c);
    else 
        f[a][b][c]=w(a-1,b,c)+w(a-1,b-1,c)+w(a,b,c-1)+w(a-1,b-1,c-1);
    return f[a][b][c];
}
int main()
{
    long long a,b,c;
    while (cin>>a>>b>>c){
        if(a==-1&&b==-1&&c==-1)
            break;
        cout<<"w("<< a<< ", "<<b<<", "<<c<<") = ";
        cout<<w(a,b,c)<<endl;
    }
    return 0;
}

改了也不行


|