-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest2.java
More file actions
33 lines (28 loc) · 801 Bytes
/
Copy pathtest2.java
File metadata and controls
33 lines (28 loc) · 801 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.util.*;
public class test2 {
public static boolean flitSub(int[] nums){
int sum = 0;
for (int i = 0; i < nums.length; i++) {
sum = sum+nums[i];
}
if(sum%2!=0) return false;
int target = sum/2;
boolean[] dp = new boolean[target+1];
dp[0] = true;
for(int num:nums){
for(int j=target; j>=num; j--){
dp[j] = dp[j]||dp[j-num];
}
}
return dp[target];
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] nums = new int[n];
for (int i = 0; i < n; i++) {
nums[i] = sc.nextInt();
}
System.out.println(flitSub(nums));
}
}