| Run ID | Author | Problem | Lang | Verdict | Time | Memory | Code Length | Submit Time |
|---|---|---|---|---|---|---|---|---|
| 89469 | sh25_zhangyj | 求和比较 | C++ | Accepted | 0 MS | 248 KB | 827 | 2026-06-05 14:27:21 |
#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; }