【记忆化搜索】P1464 Function

题目链接
题干已经提示地非常到位了

#include <cstdio>
#include<vector>
#include<algorithm>
#include<iostream>
using namespace std;
typedef long long LL;
LL w[101][101][101];
bool vis[101][101][101];
LL mw(LL a, LL b, LL c)
{
	if (a <= 0 || b <= 0 || c <= 0) return 1;
	if (a > 20 || b > 20 || c > 20) return mw(20, 20, 20); //注意,知道值就return了,否则下面的操作会改变w[a][b][c]的值
	if (vis[a][b][c]) return w[a][b][c];
	if (a < b&&b < c) w[a][b][c] = mw(a, b, c - 1) + mw(a, b - 1, c - 1) - mw(a, b - 1, c);
	else w[a][b][c] = mw(a - 1, b, c) + mw(a - 1, b - 1, c) + mw(a - 1, b, c - 1) - mw(a - 1, b - 1, c - 1);
	vis[a][b][c] = 1;
	return w[a][b][c];
}
int main()
{
	LL a, b, c;
	while (cin >> a >> b >> c)
	{
		if (a == -1 && b == -1 && c == -1) break;
		cout <<"w("<<a<<", "<<b<<", "<<c<<") = "<<mw(a,b,c) << endl;
	}
}
©️2020 CSDN 皮肤主题: 数字20 设计师:CSDN官方博客 返回首页