题目
代码
#include <bits/stdc++.h>
using namespace std;const int mod = 1000000007;//快速幂求2的x次方
long long f(int x) {long long ans = 1;long long base = 2;while (x) {if (x % 2 == 1) {ans = (ans * base) % mod; }base = (base * base) % mod;x /= 2; }return ans;
}int main() {ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);int n, m;cin >> n >> m;vector<vector<int>> dp(n + 1, vector<int>(m + 1));dp[1][1] = 1;for (int i = 1; i <= n; i++) {for (int j = 1; j <= m; j++){if (j - i > 0) {//防止越界,且最小元素为1,如果i > j 肯定不成立//dp[i][j] = 不含1的组合个数 + 含1的组合个数 dp[i][j] = (dp[i][j - i] + dp[i - 1][j - i]) % mod; }}} int ans = 1; //dp[1][m] = 1for (int i = 2; i <= n; i++) {//乘法原理:长度i总和为m的严格递增的个数 * 2 ^(i - 1)次方 ans = (ans + (long long)(dp[i][m] * f(i - 1) % mod)) % mod; } cout << ans << endl;return 0;
}