View Code of Problem 3692

#include<bits/stdc++.h> 
using namespace std;
long sum;int n;
void dfs(int from,int cur,int deep){
	if(deep==n){
		if(cur!=from)
			sum++;
		if(n==1)
			sum++;
		return ;
	}
	for(int i=0;i<=2;i++){
		if(i!=cur)
			dfs(from,i,deep+1);
	}
}
int main(){
	
	while(cin>>n){
		sum=0;
		for(int i=0;i<=2;i++){
			dfs(i,i,1);
		}
		cout<<sum<<endl;
	}
}

Double click to view unformatted code.


Back to problem 3692