Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
108945 | 彭士宝 | 求和比较 | C++ | Compile Error | 0 MS | 0 KB | 1066 | 2025-01-23 17:17:08 |
#include <iostream> #include <vector> using namespace std; int main() { int N, M; cin >> N >> M; int sum = N * (N + 1) / 2; // 计算数组的总和 // 如果M大于总和,或者总和与M的奇偶性不同,则不可能有解 if (M > sum || (sum - M) % 2 != 0) { cout << 0 << endl; return 0; } int target = (sum - M) / 2; // 计算目标子集和 vector<vector<bool>> dp(N + 1, vector<bool>(target + 1, false)); dp[0][0] = true; // 初始化 // 动态规划计算所有可能的子集和 for (int i = 1; i <= N; ++i) { for (int j = 0; j <= target; ++j) { dp[i][j] = dp[i-1][j]; // 不加入子集 if (j >= i) { dp[i][j] |= dp[i-1][j-i]; // 加入子集 } } } // 统计满足条件的方案数 int count = 0; for (int j = 0; j <= target; ++j) { if (dp[N][j] && sum - j - j == M) { count++; } } cout << count << endl; return 0; }
Main.cc: In function 'int main()': Main.cc:27:26: error: no match for 'operator|=' (operand types are 'std::vector::reference {aka std::_Bit_reference}' and 'std::vector::reference {aka std::_Bit_reference}') dp[i][j] |= dp[i-1][j-i]; // 加入子集 ^ In file included from /usr/include/c++/5/ios:42:0, from /usr/include/c++/5/ostream:38, from /usr/include/c++/5/iostream:39, from Main.cc:1: /usr/include/c++/5/bits/ios_base.h:99:3: note: candidate: const std::_Ios_Fmtflags& std::operator|=(std::_Ios_Fmtflags&, std::_Ios_Fmtflags) operator|=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b) ^ /usr/include/c++/5/bits/ios_base.h:99:3: note: no known conversion for argument 1 from 'std::vector::reference {aka std::_Bit_reference}' to 'std::_Ios_Fmtflags&' /usr/include/c++/5/bits/ios_base.h:141:3: note: candidate: const std::_Ios_Openmode& std::operator|=(std::_Ios_Openmode&, std::_Ios_Openmode) operator|=(_Ios_Openmode& __a, _Ios_Openmode __b) ^ /usr/include/c++/5/bits/ios_base.h:141:3: note: no known conversion for argument 1 from 'std::vector::reference {aka std::_Bit_reference}' to 'std::_Ios_Openmode&' /usr/include/c++/5/bits/ios_base.h:181:3: note: candidate: const std::_Ios_Iostate& std::operator|=(std::_Ios_Iostate&, std::_Ios_Iostate) operator|=(_Ios_Iostate& __a, _Ios_Iostate __b) ^ /usr/include/c++/5/bits/ios_base.h:181:3: note: no known conversion for argument 1 from 'std::vector::reference {aka std::_Bit_reference}' to 'std::_Ios_Iostate&'