Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#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
You can’t perform that action at this time.