做笔记:记忆化搜索的语法
#include<iostream> #include<cstdio> #define ll long long using namespace std; ll temp[55][55][55]; int w(ll a,ll b,ll c) { if(a<=0||b<=0||c<=0) return 1; if(a>20||b>20||c>20) { a=20; b=20; c=20; } if(temp[a][b][c]!=0) return temp[a][b][c]; else if(temp[a][b][c]==0) { if(a<b&&b<c) temp[a][b][c]=w(a,b,c-1)+w(a,b-1,c-1)-w(a,b-1,c); else temp[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); } return temp[a][b][c]; } int main() { ll a,b,c; int ans; while(scanf("%lld %lld %lld",&a,&b,&c)==3) { if(a==-1&&b==-1&&c==-1) return 0; ans=w(a,b,c); printf("w(%lld, %lld, %lld) = %d\n",a,b,c,ans); } return 0; }