6362: 2015提高阅读程序2

内存限制:256 MB 时间限制:2 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:1 通过:1

题目描述

#include <iostream> 
using namespace std; 
int k=0;
int fun(int n, int fromPos, int toPos) { 
k++;
 int t, tot; 
    if (n == 0) 
     return 0; 
    for (t = 1; t <= 3; t++) 
        if (t != fromPos && t != toPos) 
            break; 
    tot = 0; 
    tot += fun(n - 1, fromPos, t); 
    tot++; 
    tot += fun(n - 1, t, toPos); 
    return tot; 
 
int main( ) { 
    int n; 
    cin >> n; 
    cout << fun(n, 1, 3) << endl; 
    cout<<k<<endl;
    return 0; 
}

输入样例 复制


输出样例 复制