poj 1579 Function Run Fun

/* Name: poj 1579 Function Run Fun Author: Unimen Date: 07-05-11 1:16 Description: 记忆化搜索 */ /* 解题报告: 记忆化搜索 */ #include <iostream> #include <cstring> #include <cstdio> using namespace std; int anw[21][21][21]; int w(int a, int b, int c) { if(a<=0 || b<=0 || c<=0) { return 1; } if(a>20 || b>20 || c>20) { if(anw[20][20][20] != -1) return anw[20][20][20]; anw[20][20][20] = w(20, 20 ,20); return anw[20][20][20]; } if(anw[a][b][c] != -1) return anw[a][b][c]; if(a<b && b<c) return anw[a][b][c] = w(a, b, c-1) + w(a, b-1, c-1) - w(a, b-1, c); return anw[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 a, b, c; int main() { memset(anw, -1, sizeof(anw)); while(cin>>a>>b>>c && (a!=-1 || b!=-1 || c!= -1)) { printf("w(%d, %d, %d) = %d/n", a, b, c, w(a, b, c)); } return 0; }

你可能感兴趣的:(poj 1579 Function Run Fun)