标签:
bool fun(int a, int b, int c, int d)
{
if(a<0||b<0||c<0||d<0)
return false;
if((a>=3||a==0)&&(b>=3||b==0)&&(c>=3||c==0)&&(d>=3||d==0))
return true;
if(fun(a-1,b-1,c-1,d))
return true;
if(fun(a,b-1,c-1,d-1))
return true;
if(fun(a-1,b-1,c-1,d-1))
return true;
return false;
}
为避免数据过大导致栈溢出,修改为:
bool fun(int a, int b, int c, int d)
{
if(a<0||b<0||c<0||d<0)
return false;
if((a>=3||a==0)&&(b>=3||b==0)&&(c>=3||c==0)&&(d>=3||d==0))
return true;
if(fun(a-1,b-1,c-1,d-1))
return true;
if(a<=d)
{
if(fun(a-1,b-1,c-1,d))
return true;
if(fun(a,b-1,c-1,d-1))
return true;
}
else
{
if(fun(a,b-1,c-1,d-1))
return true;
if(fun(a-1,b-1,c-1,d))
return true;
}
return false;
}
标签:
原文地址:http://www.cnblogs.com/Vae98Scilence/p/4508498.html