codeforces 630C

630C - Lucky Numbers

题目大意:

给定数字位数,且这个数字只能由7和8组成,问有多少种组合的可能性

思路:

假设为1位,只有7和8;两位的时候,除了77,78,87,88之外还哇哦加上前面只有7和8的情况,一共是6位。所以递推式不难写出dp[i]=pow(2,i)+dp[i-1];

代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ans[56];
void init () {
    ans[1]=2;
    for(int i=2; i<=55; ++i) {
        ans[i]=pow(2,i)+ans[i-1];
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    init();
    int n;
    cin>>n;
    cout<<ans[n]<<endl;
    return 0;
}

原文地址:https://www.cnblogs.com/lemonbiscuit/p/7865418.html