全部超时了,请大佬们看一看,谢谢

P1464 Function

wkl20110514 @ 2022-12-19 11:43:26

全部超时了,请大佬们看一看,谢谢

#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cmath>
#define LL long long
using namespace std;
LL a[3],b;
LL w(LL a,LL b,LL 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(a<b&&b<c)return w(a,b,c-1)+w(a,b-1,c-1)-w(a,b-1,c);
    else return w(a-1,b,c)+w(a-1,b-1,c)+w(a-1,b,c-1)-w(a-1,b-1,c-1);
}
int main(){
    for(int i;i==i;){
        scanf("%lld%lld%lld",&a[0],&a[1],&a[2]);
        if(a[0]==-1&&a[1]==-1&&a[2]==-1)return 0;
        printf("w(%lld, %lld, %lld) = %lld\n",a[0],a[1],a[2],w(a[0],a[1],a[2]));
    }
}

好像输入50,50,50时时间就超了


by arrow_king @ 2022-12-19 11:48:29

记搜呢


by wkl20110514 @ 2022-12-19 11:52:04

@秦屎皇

好似

不是那么滴懂


|