|
| 1 | +```java |
| 2 | +import java.io.IOException; |
| 3 | +import java.io.*; |
| 4 | +import java.util.*; |
| 5 | + |
| 6 | + |
| 7 | +public class Main { |
| 8 | + static int studentCnt, numCnt,goal; |
| 9 | + static int[][] arr; |
| 10 | + static int[] dp; |
| 11 | + |
| 12 | + |
| 13 | + public static void main(String[] args) throws IOException { |
| 14 | + init(); |
| 15 | + process(); |
| 16 | + print(); |
| 17 | + } |
| 18 | + |
| 19 | + public static void init() throws IOException { |
| 20 | + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); |
| 21 | + StringTokenizer st = new StringTokenizer(br.readLine()); |
| 22 | + studentCnt = Integer.parseInt(st.nextToken()); |
| 23 | + numCnt =Integer.parseInt(st.nextToken()); |
| 24 | + goal = Integer.parseInt(st.nextToken()); |
| 25 | + |
| 26 | + dp = new int[goal+1]; |
| 27 | + |
| 28 | + arr = new int[studentCnt][numCnt]; |
| 29 | + for (int i = 0; i < studentCnt; i++) { |
| 30 | + st = new StringTokenizer(br.readLine()); |
| 31 | + int idx = 0; |
| 32 | + while (st.hasMoreTokens()) { |
| 33 | + arr[i][idx++] = Integer.parseInt(st.nextToken()); |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + } |
| 38 | + |
| 39 | + public static void process() throws IOException { |
| 40 | + dp[0] = 1; |
| 41 | + for (int i = 0; i < studentCnt; i++) { |
| 42 | + int[] temp = new int[goal+1]; |
| 43 | + |
| 44 | + for (int j = 0 ; j < numCnt; j++) { |
| 45 | + int num = arr[i][j]; |
| 46 | + if (num == 0) continue; |
| 47 | + for (int k = 0 ; k <= goal-num; k++) { |
| 48 | + temp[k+num] += dp[k]; |
| 49 | + } |
| 50 | + |
| 51 | + } |
| 52 | + |
| 53 | + for (int j = 0; j <= goal; j++) { |
| 54 | + dp[j] += temp[j]; |
| 55 | + dp[j] %= 10007; |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + } |
| 60 | + |
| 61 | + |
| 62 | + |
| 63 | + public static void print() { |
| 64 | + for (int j = 0; j <= goal; j++) { |
| 65 | + System.out.print(dp[j] + " "); |
| 66 | + } |
| 67 | + System.out.println(); |
| 68 | + System.out.println(dp[goal]); |
| 69 | + } |
| 70 | +} |
| 71 | + |
| 72 | +``` |
0 commit comments