【枚举子序列+组合数学+推式子】Cf Edu11 E

https://codeforces.com/contest/660/problem/E

题意:

【枚举子序列+组合数学+推式子】Cf Edu11 E_第1张图片

思路:

重点在于枚举子序列,一般是先枚举子序列长度,然后枚举别的

算是经典套路

【枚举子序列+组合数学+推式子】Cf Edu11 E_第2张图片

【枚举子序列+组合数学+推式子】Cf Edu11 E_第3张图片

【枚举子序列+组合数学+推式子】Cf Edu11 E_第4张图片

【枚举子序列+组合数学+推式子】Cf Edu11 E_第5张图片

Code:

#include 

#define int long long

using i64 = long long;

constexpr int N = 2e3 + 10;
constexpr int M = 1e6 + 10;
constexpr int P = 2600;
constexpr i64 Inf = 1e18;
constexpr int mod = 1e9 + 7;
constexpr double eps = 1e-6;

int n, m;

int qpow(int a, int b) {
    int res = 1;
    while(b) {
        if (b & 1) res = (res * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return res;
}
void solve() {
    std::cin >> n >> m;

    int ans = qpow(m, n) % mod;
    for (int j = 0; j <= n - 1; j ++) {
        ans += qpow(m, n - j) * qpow(2 * m - 1, j) % mod;
        ans %= mod;
    }

    std::cout << ans % mod << "\n";
}
signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int t = 1;

    while (t--) {
        solve();
    }
    
    return 0;
}

你可能感兴趣的:(组合数学,数学,枚举,算法)