Skip to content

Commit

Permalink
AcWing 3442. 神奇的口袋
Browse files Browse the repository at this point in the history
Signed-off-by: Tategoto Azarasi <2724167997@qq.com>
  • Loading branch information
tategotoazarasi committed Aug 27, 2024
1 parent 40820ed commit fc32da3
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
26 changes: 26 additions & 0 deletions acwing408.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1865,4 +1865,30 @@ namespace acwing {
return 0;
}
}// namespace acwing3445

/**
* @brief 3442. 神奇的口袋
*/
namespace acwing3442 {
int main(istream &cin, ostream &cout) {
int n;
cin >> n;
vector<int> a(n);
for(int i = 0; i < n; i++) {
cin >> a[i];
}
vector<vector<int>> dp(n + 1, vector<int>(41, 0));
dp[0][0] = 1;
for(int i = 1; i <= n; i++) {
for(int j = 0; j <= 40; j++) {
dp[i][j] = dp[i - 1][j];
if(j >= a[i - 1]) {
dp[i][j] += dp[i - 1][j - a[i - 1]];
}
}
}
cout << dp[n][40];
return 0;
}
}// namespace acwing3442
}// namespace acwing
7 changes: 7 additions & 0 deletions acwing408.h
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,13 @@ namespace acwing {
};
int main(istream & /*cin*/, ostream & /*cout*/);
}// namespace acwing3445

/**
* @brief 3442. 神奇的口袋
*/
namespace acwing3442 {
int main(istream & /*cin*/, ostream & /*cout*/);
}// namespace acwing3442
}// namespace acwing

#endif//PROBLEMSCPP_ACWING408_H
44 changes: 44 additions & 0 deletions acwing408_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2044,4 +2044,48 @@ namespace acwing {
ASSERT_EQ("298", ans);
}
}// namespace acwing3445

/**
* @brief 3442. 神奇的口袋
*/
namespace acwing3442 {
TEST(acwing3442, case1) {
istringstream in("3\n"
"20\n"
"20\n"
"20");
auto out = ostringstream();
main(in, out);
const auto ans = out.str();
ASSERT_EQ("3", ans);
}

TEST(acwing3442, case2) {
istringstream in("20\n"
"1\n"
"2\n"
"2\n"
"5\n"
"4\n"
"5\n"
"5\n"
"2\n"
"3\n"
"5\n"
"1\n"
"4\n"
"3\n"
"5\n"
"4\n"
"3\n"
"3\n"
"2\n"
"3\n"
"5");
auto out = ostringstream();
main(in, out);
const auto ans = out.str();
ASSERT_EQ("37564", ans);
}
}// namespace acwing3442
}// namespace acwing

0 comments on commit fc32da3

Please sign in to comment.