Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
110117 彭士宝 求和比较 C++ Compile Error 0 MS 0 KB 981 2025-02-14 18:10:00

Tests(0/0):


Code:

#include <iostream> #include <vector> using namespace std; int main() { int N, M; cin >> N >> M; // 计算总和 int S = N * (N + 1) / 2; // 如果 S + M 是奇数,直接返回 0 if ((S + M) % 2 != 0) { cout << 0 << endl; return 0; } // 目标和 int target = (S + M) / 2; // 初始化 DP 数组 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 i = 1; i <= N; ++i) { if (dp[i][target]) { count++; } } cout << count << endl; return 0; }


Run Info:

Main.cc: In function 'int main()':
Main.cc:30: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&'