P2907 [USACO08OPEN]农场周围的道路Roads Around The Farm
基础dfs,按题意递归即可。
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #define re register 5 using namespace std; 6 int n,k,ans; 7 void dfs(int x){ 8 if(x<=k||((x-k)&1)){//不能有半只奶牛(大雾) 9 ++ans; return; 10 }dfs((x-k)/2); dfs((x-k)/2+k);//分成2群 11 } 12 int main(){ 13 scanf("%d%d",&n,&k);dfs(n); 14 printf("%d",ans); 15 return 0; 16 }