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;
}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-07
  • 2022-12-23
  • 2022-12-23
  • 2021-08-15
  • 2022-03-06
  • 2021-09-27
猜你喜欢
  • 2022-12-23
  • 2021-11-06
  • 2022-02-25
  • 2021-10-17
  • 2022-12-23
  • 2021-12-04
  • 2022-01-26
相关资源
相似解决方案