Functionc++代码

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=25;
const int T=1000;
int x[T][4];
long long ans[T];
bool vis[N][N][N];
long long mem[N][N][N];
long long w(int a, int b, int c){
    long long ans;
    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(vis[a][b][c]) return mem[a][b][c];
    /*如果a< b并且b< c  就返回w(a,b,c-1)+w(a,b-1,c-1)-w(a,b-1,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)*/
    if(a<b && b<c){
        ans=w(a,b,c-1)+w(a,b-1,c-1)-w(a,b-1,c);
    }else{
        ans=w(a-1,b,c)+w(a-1,b-1,c)+w(a-1,b,c-1)-w(a-1,b-1,c-1);
    }
    vis[a][b][c]=true;
    return mem[a][b][c]=ans;
}
int main(){
    int cnt=0;
    int a,b,c;
    scanf("%d %d %d", &a,&b,&c);
    while(!(a==-1 && b==-1 && c==-1)){
        ++cnt;
        x[cnt][1]=a,x[cnt][2]=b,x[cnt][3]=c;
        ans[cnt]=w(a,b,c);       
        scanf("%d %d %d", &a,&b,&c);    //输入
    }
    for(int i=1;i<=cnt;i++)
        printf("w(%d, %d, %d) = %d\n", x[i][1],x[i][2],x[i][3],ans[i]);    //输出
    return 0;
}

  • 12
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值