急救!!!

P1464 Function

hanciyang @ 2023-12-30 13:48:33

记录:记录

#include <bits/stdc++.h>
using namespace std ;
int a,b,c , f [30] [30] [30];
int dfs (int a , int b , int c) 
{
    if (a <= 0 || b <= 0 || c <= 0)  return 1 ;
    if (a > 20 || b > 20 || c > 20) return  dfs (20,20,20) ;
    if (f [a] [b] [c])  return f [a] [b] [c] ;
    else if (a < b && b < c) 
        return  f [a] [b] [c] = dfs (a , b , c - 1) + dfs (a , b - 1 , c - 1)- dfs (a , b - 1 , c) ;
    else
        return  f [a] [b] [c] = dfs (a - 1 , b , c) + dfs (a - 1 , b - 1 , c)+ dfs (a - 1 , b , c - 1) - dfs (a - 1 , b - 1 , c - 1);
}
int main ()
{
    while (1)
    {
        cin >> a >> b >> c ;
        if (a == -1 && b == -1 && c == -1)  break ;
        cout << "w("<<a<<", "<<b<<", "<<c<<") = "<<dfs (a , b , c)<<"\n" ;
    }
}

by Pitiless_boy @ 2023-12-30 13:51:00

#include <bits/stdc++.h>
#define int long long
using namespace std;
int n[130][130][130];
int dg(int a, int b, int c) {
    if (a <= 0 || b <= 0 || c <= 0)
        return 1;
    else if (n[a][b][c] != 0)
        return n[a][b][c];
    else if (a > 20 || b > 20 || c > 20)
        n[a][b][c] = dg(20, 20, 20);
    else if (a < b && b < c)
        n[a][b][c] = dg(a, b, c - 1) + dg(a, b - 1, c - 1) + dg(a, b - 1, c);
    else return dg(a - 1, b, c) + dg(a - 1, b - 1, c) + dg(a - 1, b, c - 1) - dg(a - 1, b - 1, c - 1);
    return n[a][b][c];
}
signed main() {
    int a, b, c;
    while (cin >> a >> b >> c) {
        if (a == b && b == c && c == -1)
            break;
        int p = 0;
        cout << "w(" << a << ", " << b << ", " << c << ") = ";
        if (a > 20)
            a = 21;
        if (b > 20)
            b = 21;
        if (c > 20)
            c = 21;
        p = dg(a, b, c);
        cout << p << endl;
    }
    return 0;
}

by hanciyang @ 2023-12-30 13:56:29

@Pitiless_boy 谢,没开long long 记录


by Pitiless_boy @ 2023-12-30 13:57:03

@hanciyang ok


|