https://codeforces.com/contest/660/problem/E
题意:
思路:
重点在于枚举子序列,一般是先枚举子序列长度,然后枚举别的
算是经典套路
Code:
#include <bits/stdc++.h>
#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;
}