ZOJ 1539 Lot(DFS)

来源:互联网 发布:2017程序员就业现状 编辑:程序博客网 时间:2024/04/28 01:27

直接照着题意搜了.

#include <iostream>#include <memory.h>#include <cstdio>using namespace std;int ans,n;void dfs(int c){if(c == 3){ans++;}else if(c < 3){return;}if(c % 2){//当前数量是奇数 dfs(c - c / 2);//偶数 dfs(c - c/ 2 - 1);//奇数 }else{//当前数量是偶数 int anst = ans;dfs(c - c / 2);//因为奇数和偶数都是一样的,所以再加一次就可以了,不用再继续dfs. ans += ans - anst;}}int main(){while(scanf("%d",&n) == 1){ans = 0;dfs(n);printf("%d\n",ans);}return 0;}


原创粉丝点击