zufeoj_递归求猴子吃桃

题目链接:http://acm.ocrosoft.com/problem.php?cid=1172&pid=12


题目描述

猴子吃桃问题。猴子第1天摘下若干个桃子,当即吃了一半,还不过瘾,又多吃了一个。第2天早上又将剩下的桃子吃掉一半,又多吃了一个。以后每天早上都吃了前一天剩下的一半另加一个。到第n天早上想再吃时,就只剩下一个桃子了。求第1天共摘了多少个桃子

输入

n的值

输出

剩下的桃子数量

样例输入

10

样例输出

total=1534


#include<bits/stdc++.h>
using namespace std;
int n;
int f(int t){
    if(t==1){
        return 1;
    }else{
        return 2*(f(t-1)+1);
    }
}
int main(){
    cin>>n;
    cout<<"total="<<f(n)<<endl;
    return 0;
}


猜你喜欢

转载自blog.csdn.net/m0_37345402/article/details/80753233