fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Codechef
  6. {
  7. public static void main (String[] args) throws java.lang.Exception
  8. {
  9. // your code goes here
  10. Scanner sc=new Scanner(System.in);
  11. int t=sc.nextInt();
  12. while(t-->0){
  13. int n=sc.nextInt();
  14. int y=sc.nextInt();
  15. int [] ar=new int[n];
  16. for(int i=0;i<n;i++){
  17. ar[i]=sc.nextInt();
  18. }
  19. int ok=solve(ar,y);
  20. System.out.println(ok);
  21. }
  22. sc.close();
  23. }
  24.  
  25. public static int solve(int []ar,int y){
  26. int [][] dp=new int[ar.length+1][y+1];
  27. dp[0][0]=1;
  28. for(int i=1;i<=ar.length;i++){
  29. for(int j=0;j<=y;j++){
  30. dp[i][j] = dp[i - 1][j];
  31. if (j >= ar[i - 1]) {
  32. dp[i][j] += dp[i - 1][j - ar[i - 1]];
  33. }
  34. }
  35. }
  36. return dp[ar.length][y];
  37. }
  38. }
  39.  
Success #stdin #stdout 0.14s 56624KB
stdin
3
5 9
6 3 6 5 1
5 50
6 3 6 5 1
5 6
6 3 6 5 1
stdout
3
0
3