CSES - Shared codeLink to this code:
https://cses.fi/paste/5ca0826685e6ac102c689b/
import java.util.Scanner;
class practice{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int m = (int)1e9+7;
int n = in.nextInt();
int tar = in.nextInt();
int[] arr = new int[n];
for(int i=0;i<n;i++)
arr[i] = in.nextInt();
int[] dp = new int[tar+1];
dp[0]=1;
for(int i=1;i<=tar;i++) {
for(int j=0;j<n;j++)
if(i-arr[j] >=0)
dp[i] = (dp[i] + dp[i-arr[j]])%m;
}
System.out.println(dp[tar]);
}
}