树形递归——1621: [Usaco2008 Open]Roads Around The Farm
Posted on 2011-07-26 16:06 huhuuu 阅读(261) 评论(0) 编辑 收藏 举报想下递归过程
注意位运算优先级小,加括号
View Code
#include<stdio.h>
int k;
int dfs(int left)
{
if((left-k)<=1||((left-k)%2)==1)
{
return 1;
}
return dfs((left-k)>>1)+dfs(left-((left-k)>>1));
}
int main()
{
int n;
while(scanf("%d%d",&n,&k)!=EOF)
{
printf("%d\n",dfs(n));
}
}