File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.io.* ;
3+ import java.util.* ;
4+
5+ public class Main {
6+
7+ public static void main (String [] args ) throws IOException {
8+ BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
9+ StringTokenizer st;
10+
11+ int n = Integer . parseInt(br. readLine());
12+ int [] arr = new int [n];
13+ long [][] dp = new long [n - 1 ][21 ];
14+
15+ st = new StringTokenizer (br. readLine());
16+ for (int i = 0 ; i < n; i++ ) {
17+ arr[i] = Integer . parseInt(st. nextToken());
18+ }
19+
20+ dp[0 ][arr[0 ]] = 1 ;
21+
22+ for (int i = 1 ; i < n - 1 ; i++ ) {
23+ for (int j = 0 ; j <= 20 ; j++ ) {
24+ int plus = j + arr[i];
25+ int minus = j - arr[i];
26+
27+ if (plus <= 20 )
28+ dp[i][plus] += dp[i - 1 ][j];
29+ if (minus >= 0 )
30+ dp[i][minus] += dp[i - 1 ][j];
31+ }
32+ }
33+
34+ System . out. println(dp[n - 2 ][arr[n - 1 ]]);
35+ }
36+ }
37+ ```
You can’t perform that action at this time.
0 commit comments