Submission
# | When | Author | Problem | Language | CPU | Memory | |
---|---|---|---|---|---|---|---|
20811 | 2024-06-03 01:35:33 | AHAMMED_99 | The Picky Penguins' Party | C | 9 ms | 1500 kb | Accepted |
Source Code
#include <stdio.h> #include <stdlib.h> // Function to check if array can be partitioned into two subsets of equal sum int canPartition(int* nums, int numsSize) { long long sum = 0; for (int i = 0; i < numsSize; i++) { sum += nums[i]; } // If sum is odd, it's not possible to partition into two equal subsets if (sum % 2 != 0) { return 0; } int target = sum / 2; dp[0] = 1; for (int i = 0; i < numsSize; i++) { for (int j = target; j >= nums[i]; j--) { dp[j] = dp[j] || dp[j - nums[i]]; } } int result = dp[target]; return result; } int main() { int T; while (T--) { int N; for (int i = 0; i < N; i++) { } if (canPartition(A, N)) { } else { } } return 0; }