欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

HDU 1331(Function Run Fun)

程序员文章站 2022-07-12 08:54:32
...

直接暴力打表即可。

#include <iostream>
using namespace std;
const int MAXN = 25;

int f[MAXN][MAXN][MAXN]; //记录w(a,b,c)

//计算w(a,b,c)
void w(int a, int b, int c)
{
    if (a <= 0 || b <= 0 || c <= 0)
        f[a][b][c] = 1;
    else if (a < b && b < c)
        f[a][b][c] = f[a][b][c - 1] + f[a][b - 1][c - 1] - f[a][b - 1][c];
    else
        f[a][b][c] = f[a - 1][b][c] + f[a - 1][b - 1][c] + f[a - 1][b][c - 1] - f[a - 1][b - 1][c - 1];
}

int main()
{
    for (int i = 0; i <= 20; i++) //打表
    {
        for (int j = 0; j <= 20; j++)
            for (int k = 0; k <= 20; k++)
                w(i, j, k);
    }

    int a, b, c;
    while (cin >> a >> b >> c)
    {
        if (a == -1 && b == -1 && c == -1)
            break;

        cout << "w(" << a << ", " << b << ", " << c << ") = ";
        if (a <= 0 || b <= 0 || c <= 0)
            cout << 1 << endl;
        else if (a > 20 || b > 20 || c > 20)
            cout << f[20][20][20] << endl;
        else
            cout << f[a][b][c] << endl;
    }
    return 0;
}

继续加油。

相关标签: HDU