[Los] Function Valley p1464

The test on the first day;

I feel super waste;

This question is particularly pleasing to the eye is to see emmm

SOLUTION:

Thought it is an open three-dimensional array s [i] [j] [k], the first triple for circulating preprocessing the s [0 ~ 20] [0 ~ 20] [0 ~ 20] of w (a, b, c), then search directly enough.

Code:

#include<bits/stdc++.h>

using namespace std;

long long a,b,c;
long long s[21][21][21];

long long w(long long a,long long b,long long c){
    if(a<=0||b<=0||c<=0) return 1;
    if(a<b&&b<c) s[a][b][c]=s[a][b][c-1]+s[a][b-1][c-1]-s[a][b-1][c];
    else s[a][b][c]=s[a-1][b][c]+s[a-1][b-1][c]+s[a-1][b][c-1]-s[a-1][b-1][c-1];
    return s[a][b][c];
}

void ycl(){
    for(int i=0;i<=20;i++){
        for(int j=0;j<=20;j++){
            for(int k=0;k<=20;k++){
                s[i][j][k]=w(i,j,k);
            }
        }
    }
}

long long dfs(long long a,long long b,long long c){
    if(a<=0||b<=0||c<=0) return 1;
    if(a>20||b>20||c>20) return s[20][20][20];
    return s[a][b][c];
}


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

 

Guess you like

Origin www.cnblogs.com/zhuier-xquan/p/11004647.html