Untitled
unknown
plain_text
a year ago
1.2 kB
5
Indexable
public class Solution { static final int mn = 2003; static int[][] a = new int[mn][mn]; static int[] no = new int[mn]; static int n, res, k, s, check; static void Try(int sl, int sum) { if (sl == k + 1) { if (sum == s) { check += 1; } return; } for (int i = 1; i <= n; i++) { no[sl] = i; if (a[i][sl] >= a[no[sl - 1]][sl - 1] && s >= sum + a[i][sl]) Try(sl + 1, sum + a[i][sl]); } } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int te = sc.nextInt(); for (int tes = 1; tes <= te; tes++) { System.out.println("Case " + tes); check = -1; res = 0; s = sc.nextInt(); k = sc.nextInt(); n = sc.nextInt(); for (int i = 1; i <= n; i++) { for (int j = 1; j <= k; j++) { a[i][j] = sc.nextInt(); } } Try(1, 0); if (check > -1) check++; System.out.println(check); } sc.close(); } }
Editor is loading...
Leave a Comment