zoukankan      html  css  js  c++  java
  • poj1579

    记忆化搜索

    View Code
    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    using namespace std;
    
    #define maxn 25
    
    int a, b, c;
    int f[maxn][maxn][maxn];
    
    int w(int a, int b, int c)
    {
        if (a <= 0 || b <= 0 || c <= 0)
            return 1;
        if (a > 20 || b > 20 || c > 20)
            return w(20, 20, 20);
        if (f[a][b][c] != -1)
            return f[a][b][c];
        if (a < b && b < c)
            return 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] = 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()
    {
        memset(f, -1, sizeof(f));
        //freopen("t.txt", "r", stdin);
        while (scanf("%d%d%d", &a, &b, &c), ~a | ~b | ~c)
            printf("w(%d, %d, %d) = %d\n", a, b, c,  w(a, b, c));    
        return 0;
    }
  • 相关阅读:
    javase 超市库存系统
    Javase 简单代码练习
    Javase 简单练习
    SQL表连接查询
    SQL多表查询
    SQL表查询
    SQL数据查询2
    SQL数据查询
    SQL增删改
    AutoCompleteTextView的使用
  • 原文地址:https://www.cnblogs.com/rainydays/p/2861707.html
Copyright © 2011-2022 走看看