您的位置:首页 > 其它

POJ 1579 解题报告

2015-05-16 05:11 309 查看
简单题

thestoryofsnow1579Accepted184K0MSC++1247B
/*
ID: thestor1
LANG: C++
TASK: poj1579
*/
#include <iostream>
#include <fstream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <limits>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <cassert>

using namespace std;

const int MAXN = 21;

bool isSet[MAXN][MAXN][MAXN] = {{{false}}};
int cache[MAXN][MAXN][MAXN];

int recursion(int a, int b, int c)
{
if (a <= 0 || b <= 0 || c <= 0)
{
return 1;
}

if (a > 20 || b > 20 || c > 20)
{
return recursion(20, 20, 20);
}

if (isSet[a][b][c])
{
return cache[a][b][c];
}

int ret;
if (a < b && b < c)
{
ret = recursion(a, b, c - 1) + recursion(a, b - 1, c - 1) - recursion(a, b - 1, c);
}
else
{
ret = recursion(a - 1, b, c) + recursion(a - 1, b - 1, c) + recursion(a - 1, b, c - 1) - recursion(a - 1, b - 1, c - 1);
}
cache[a][b][c] = ret;
isSet[a][b][c] = true;
return ret;
}

int main()
{
int a, b, c;
while (scanf("%d%d%d", &a, &b, &c))
{
if (a == -1 && b == -1 && c == -1)
{
break;
}
printf("w(%d, %d, %d) = %d\n", a, b, c, recursion(a, b, c));
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: