-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEx 5.java
More file actions
52 lines (47 loc) · 1.32 KB
/
Ex 5.java
File metadata and controls
52 lines (47 loc) · 1.32 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import java.util.Scanner;
import java.lang.String;
public class Main {
final int N = 22, M = 22;
public static int[] Calculate (int n, int m, int[] a) {
final int N = 22, M = 22;
int[][] A = new int[N*M][N];
for(int i = 0; i < N * M; i++){
for(int j = 0; j < N; j++){
A[i][j] = 0;
}
}
A[0][0] = 1;
for(int j = 1; j <= n; j++){
for(int i = 0; i <= n * m; i++){
for(int k = 0; k <= i; k++){
A[i][j] += A[k][j-1] * a[i - k];
}
}
}
int[] ans = new int[N*M];
for(int i = 0; i <= n * m; i++){
ans[i] = A[i][n];
}
return ans;
}
public static void main(String[] args) {
final int N = 22, M = 22;
Scanner cs = new Scanner(System.in);
int m = cs.nextInt();
int n = cs.nextInt();
int[] a = new int[N*M];
for(int i = 0; i <= m; i++){
a[i]=cs.nextInt();
}
for(int i = m + 1; i <= n * m; i++){
a[i] = 0;
}
int[] ans = Calculate(n, m, a);
for(int i = 0; i <= n * m; i++){
System.out.print( ans[i]);
if(i + 1 <= n * m){
System.out.print(' ');
}
}
}
}