https://www.luogu.com.cn/problem/P1464
- 单个返回条件的时候,直接return
- 多个返回条件的时候,采用记忆化搜索思想,边存储边继续往下搜索
- 中间穿插记忆化判断,如果之前有过此类记录,直接拿来用,没有的话就继续往下搜索
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18;
const LL N=500200,M=202;
int mp[M][M][M];
LL dfs(LL x,LL y,LL z)
{
if(x<=0||y<=0||z<=0) return 1;
if(x>20||y>20||z>20) return dfs(20,20,20);
if(mp[x][y][z]) return mp[x][y][z];
if(x<y&&y<z) return mp[x][y][z]=dfs(x,y,z-1)+dfs(x,y-1,z-1)-dfs(x,y-1,z);
else return mp[x][y][z]=dfs(x-1,y,z)+dfs(x-1,y-1,z)+dfs(x-1,y,z-1)-dfs(x-1,y-1,z-1);
}
int main()
{
cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
//init();
LL T=1;
//cin>>T;
while(T--)
{
LL x,y,z;
while(cin>>x>>y>>z)
{
if(x==-1&&y==-1&&z==-1) break;
cout<<"w("<<x<<", "<<y<<", "<<z<<") = "<<dfs(x,y,z)<<endl;
}
}
return 0;
}
标签:Function,洛谷,P1464,LL,dfs,return,搜索,20
From: https://www.cnblogs.com/Vivian-0918/p/16845926.html