Title: Click here
: This problem can first DFS deep search, regular DP
Dfs:
1#include <bits/stdc++.h>2 using namespacestd;3 #defineS Second4typedefLong Longll;5 Const intINF =0x3f3f3f3f;6 Const intM = 1e5+3;7 8 ints;9 intCNT =0;Ten BOOLvis[ -]; One voidDfsintLastintnum) { A if(num = =s) { -cnt++; - return ; the } - for(intI=2; i<s+1; i++ ) - if(ABS (LAST-I) <=2&&!Vis[i]) { -Vis[i] =true; +DFS (i, num+1 ); -Vis[i] =false; + } A } at intMain () { - while(~SCANF ("%d", &s)) { -memset (Vis,false,sizeof(Vis)); -CNT =0; -vis[1] =true; -Dfs1,1 ); inprintf"%d\n", CNT); - } to return 0; +}
View Code
Dp:
1#include <bits/stdc++.h>2 using namespacestd;3 #defineF First4 #defineS Second5typedef unsignedLong Longll;6 Const intINF =0x3f3f3f3f;7 Const intM = 1e5+3;8 9 ints;Tenll dp[ -]; One voidPre () { AMemset (DP,0,sizeof(DP)); -dp[1] =1; -dp[2] =1; thedp[3] =2; -dp[4] =4; - for(intI=5; i<= -; i++ ) -Dp[i] = dp[i-1]+dp[i-3]+1; + } - intMain () { + pre (); A while(~SCANF ("%d", &s)) { atprintf"%i64d\n", Dp[s]); - } - return 0; -}
URAL 1260 Nudnik photographer DFS DP