hdu-2045 recursion

#include <cstdio>
#include <iostream>
using namespace std;
long long a[55] = {0,3,6};
long long b[55] = {0,0,0,6};
long long int fun(int x);
long long int funa(int x);

long long int fun(int x){
	if(a[x]) return a[x];
	return a[x] = funa(x-1) * 2 + fun(x-1);
}

 
long long int funa(int x){
	if(b[x]) return b[x];
	if(x <= 2) return 0;
	
	return b[x] = fun(x-1);
}
int main(){
	
	int n;
	fun(50);
	while(cin >> n){
		printf("%I64d\n",a[n]);
	}
	return 0;
	
}

Although this question seems very easy. But it does use the recursive method of two paths at the same time!

Considered very novel, such two recursive approaches give me the very good fact that a recursive problem can be solved with a problem that also relies on recursion.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324725888&siteId=291194637