题目描述
package dp;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class 数字组合 {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(System.in));
String p[]=bufferedReader.readLine().split(" ");
int n=Integer.parseInt(p[0]);
int m=Integer.parseInt(p[1]);
int a[]=new int [n+1];
p=bufferedReader.readLine().split(" ");
for(int i=1;i<=n;i++){
a[i]=Integer.parseInt(p[i-1]);
}
int f[][]=new int [n+1][m+1];
f[0][0]=1;
for(int i=1;i<=n;i++){
for(int j=0;j<=m;j++){
f[i][j]=f[i-1][j];
if(j>=a[i]){
f[i][j]+=f[i-1][j-a[i]];
}
}
}
System.out.println(f[n][m]);
}
}