Skip to content

Instantly share code, notes, and snippets.

@jwon0615 jwon0615/2641.cpp
Created May 29, 2018

Embed
What would you like to do?
#include <stdio.h>
int n,sum;
void dfs(int k, int p1, int p2){
if(k>n) return;
if(k==n) {
sum++; return;
}
if((p1==3) or (p2==3)){
dfs(k+1,p2,1);
dfs(k+2,p2,2);
}
else{
dfs(k+1,p2,1);
dfs(k+2,p2,2);
dfs(k+3,p2,3);
}
}
int main(){
scanf("%d", &n);
dfs(0,0,0);
printf("%d", sum);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.