POJ 1597 Function Run Fun

记忆化搜索。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<string>
#include<iostream>
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<X,bool>f;
map<X,int>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 <= || y <= || z <= ) w[X(x,y,z)]=;
else if(x > || y > || z > ) w[X(x,y,z)] = work(,,);
else if(a < b && b < c) w[X(x,y,z)] =work(x, y, z-) + work(x, y-, z-) - work(x, y-, z);
else w[X(x,y,z)] = work(x-, y, z) + work(x-, y-, z) + work(x-, y, z-) - work(x-, y-, z-); return w[X(x,y,z)];
} int main()
{
while(~scanf("%d%d%d",&a,&b,&c))
{
if(a==-&&b==-&&c==-) break;
printf("w(%d, %d, %d) = %d\n",a,b,c,work(a,b,c));
} return ;
}
上一篇:[翻译] 编写高性能 .NET 代码--第二章 GC -- 避免使用终结器,避免大对象,避免复制缓冲区


下一篇:Linux内核驱动之GPIO子系统(一)GPIO的使用