Skip to content

Instantly share code, notes, and snippets.

@jwon0615
Created May 29, 2018 05:01
Show Gist options
  • Save jwon0615/fed1ad8613735eeba2e2183826629fae to your computer and use it in GitHub Desktop.
Save jwon0615/fed1ad8613735eeba2e2183826629fae to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <queue>
using namespace std;
queue<int> q;
int n,sum,d;
void dfs(int k){
if(k>n) return;
if(k==d) return;
if(k==n) {
sum++; return;
}
dfs(k+1);
dfs(k+2);
dfs(k+3);
}
void bfs(int k) {
q.push(k);
while(!q.empty()){
int nx=q.front();
q.pop();
if(nx<n){
q.push(nx+1);
q.push(nx+2);
}
else if(nx==n) sum++;
}
}
int main(){
scanf("%d %d", &n, &d);
dfs(0);
printf("%d", sum);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment