存疑

P1464 Function

2740gogo @ 2024-03-02 23:34:48

//tag:记忆化
//Q1:a,b,c可以不需要数组,反复赋值即可
//Q2:a=1&&b=1的反面是a!=1||b!=1
//Q3:看清题意是与还是或
//Q3:cin默认int输入类型,用scanf输入才行
//Q4:scanf("%lld%lld%lld",&a,&b,&c);注意ll和引号
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
ll dp[25][25][25];
ll func(ll a,ll b,ll c)
{
    if (dp[a][b][c])return dp[a][b][c];
    if (a<=0||b<=0||c<=0)return 1;
    if (a>20||b>20||c>20)return func(20,20,20);
    if (a<b&&b<c) return dp[a][b][c]=func(a,b,c-1)+func(a,b-1,c-1)-func(a,b-1,c);
    else return dp[a][b][c]=func(a-1,b,c)+func(a-1,b-1,c)+func(a-1,b,c-1)-func(a-1,b-1,c-1);

}
int main(){
    ll a,b,c;
    scanf("%lld%lld%lld",&a,&b,&c);
    while (a!=-1||b!=-1||c!=-1)
    {
        cout<<"w("<<a<<", "<<b<<", "<<c<<") = "<<func(a,b,c)<<endl;
         scanf("%lld%lld%lld",&a,&b,&c);
}
    return 0;
}

请问有人知道为什么结果不对吗


by snowball10185 @ 2024-03-04 20:56:10

你有一个地方写错了


by snowball10185 @ 2024-03-04 20:59:33

if(a<b&&b<c)那里应该是 func(a,b,c-1)+func(a,b-1,c)-func(a,b-1,c)


by 2740gogo @ 2024-03-15 00:34:43

@snowball10185 谢谢


|