Run ID 作者 问题 语言 测评结果 时间 内存 代码长度 提交时间
71156 sh25_zhoumy 求和比较 C++ 通过 0 MS 248 KB 829 2025-10-24 15:21:23

Tests(1/1):


#include <iostream> #include <vector> #include <cmath> using namespace std; int main() { int N, M; cin >> N >> M; int total_sum = N * (N + 1) / 2; vector<vector<long long>> dp(N + 1, vector<long long>(total_sum + 1, 0)); dp[0][0] = 1; for (int i = 1; i <= N; i++) { for (int j = 0; j <= total_sum; j++) { if (j + i <= total_sum) { dp[i][j] += dp[i - 1][j + i]; } dp[i][j] += dp[i - 1][abs(j - i)]; } } long long result; if (M == 0) { // 当M=0时,需要除以2,因为每个方案被计算了两次 result = dp[N][M] / 2; } else { result = dp[N][M]; } cout << result << endl; return 0; }


测评信息: