本文共 1017 字,大约阅读时间需要 3 分钟。
记忆化搜索。
#include #include #include #include #include #include #include #include #include using namespace std;struct X{ int x,y,z; X(int xx,int yy,int zz) { x=xx; y=yy; z=zz; } bool operator < (const X &a) const { if(x!=a.x) return x>a.x; if(y!=a.y) return y>a.y; return z>a.z; }};int a,b,c;map f;map w;int work(int x,int y,int z){ if(f[X(x,y,z)]) return w[X(x,y,z)]; f[X(x,y,z)]=true; if(x <= 0 || y <= 0 || z <= 0) w[X(x,y,z)]=1; else if(x > 20 || y > 20 || z > 20) w[X(x,y,z)] = work(20,20,20); else if(a < b && b < c) w[X(x,y,z)] =work(x, y, z-1) + work(x, y-1, z-1) - work(x, y-1, z); else w[X(x,y,z)] = work(x-1, y, z) + work(x-1, y-1, z) + work(x-1, y, z-1) - work(x-1, y-1, z-1); return w[X(x,y,z)];}int main(){ while(~scanf("%d%d%d",&a,&b,&c)) { if(a==-1&&b==-1&&c==-1) break; printf("w(%d, %d, %d) = %d\n",a,b,c,work(a,b,c)); } return 0;}
转载于:https://www.cnblogs.com/zufezzt/p/6814442.html