美文网首页
2020-08-14 Function

2020-08-14 Function

作者: JalorOo | 来源:发表于2020-08-14 21:40 被阅读0次

https://www.luogu.com.cn/problem/P1464

#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstring>
using namespace std;

long long qmi(int m, int k)
{
    int res = 1, t = m;
    while (k)
    {
        if (k&1) res = res * t;
        t = t * t;
        k >>= 1;
    }
    return res;
}

int read(){
    int x = 0,f = 1;
    char c = getchar();
    while (c<'0'||c>'9') {
        if (c=='-') {
            f = -1;
        }
        c = getchar();
    }
    while (c>='0'&&c<='9') {
        x = x*10+c-'0';
        c = getchar();
    }
    return x*f;
}


void out(long long a, long long b, long long c,long long ans){
    cout<<"w("<<a<<", "<<b<<", "<<c<<") = "<<ans<<endl;
}

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){
        if(f[20][20][20]==0)
            f[20][20][20] = w(20,20,20);
        return f[20][20][20];
    }
    else if(a < b && b < c){
        if(f[a][b][c]==0)
            f[a][b][c] = w(a,b,c-1)+w(a,b-1,c-1)-w(a,b-1,c);
        return f[a][b][c];
    }
    if(f[a][b][c]==0)
        f[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 f[a][b][c];
}


int main(){
    while (1) {
        long long a ;
        long long b ;
        long long c ;
        cin>>a>>b>>c;
        if(a == -1 && b == -1 && c == -1){//终止条件
            break;
        }
        out(a, b, c, w(a,b,c));
    }
    return 0;
}
/*
3
 
============
5
*/

相关文章

网友评论

      本文标题:2020-08-14 Function

      本文链接:https://www.haomeiwen.com/subject/zoindktx.html