(水题)洛谷 - P1464 - Function
https://www.luogu.org/problemnew/show/P1464
#include<bits/stdc++.h> using namespace std; #define ll long long ll a,b,c; map<ll,int> m; int dfs(ll a,ll b,ll c){ if(a<=0||b<=0||c<=0) return 1; if(a>20||b>20||c>20) return dfs(20,20,20); ll p=10000*a+100*b+c; if(m.count(p)) return m[p]; else if(a<b&&b<c){ int t=dfs(a,b,c-1)+dfs(a,b-1,c-1)-dfs(a,b-1,c);; m[p]=t; return t; } else{ int t=dfs(a-1,b,c)+dfs(a-1,b-1,c)+dfs(a-1,b,c-1)-dfs(a-1,b-1,c-1); m[p]=t; return t; } } int main(){ while(cin>>a>>b>>c){ if(a==-1&&b==-1&&c==-1) return 0; else{ printf("w(%lld, %lld, %lld) = %d\n",a,b,c,dfs(a,b,c)); } } }