标签:
Description
Input
Output
Sample Input
input | output |
---|---|
4 |
4 |
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; int vis[60]; int n; int ans; void dfs(int m,int num) { if(num == n){ ans++; return ; } for(int i = m - 2; i <= m + 2; i++){ if(i <= 1 || i > n ) continue; if(!vis[i]){ vis[i] = 1; dfs(i,num+1); vis[i] = 0; } } } int main() { while(~scanf("%d",&n)){ ans = 0; memset(vis,0,sizeof(vis)); vis[1] = 1; dfs(1,1); printf("%d\n",ans); } return 0; }
AC代码
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; int dp[60]; int main() { int n; dp[1] = 1; dp[2] = 1; dp[3] = 2; while(~scanf("%d",&n)){ for(int i = 3; i <= n ;i++) dp[i] = dp[i-1] + dp[i-3] + 1; printf("%d\n",dp[n]); } return 0; }
URAL——DFS找规律——Nudnik Photographer
标签:
原文地址:http://www.cnblogs.com/zero-begin/p/4484933.html