思想
f[i][j]表示摆放前i种花,摆放了j盆的方案数。注意在遍历k的时候,k指的是第i种花用了多少盆,所以前i-1盆用的是j-k盆
代码
import java.io.*;
public class Main {
static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
static int N = 110, mod = (int)1e6+7;
static int[][] f = new int[N][N];
static int[] a = new int[N];
public static void main(String[] args)throws IOException{
int n = nextInt(), m = nextInt();
for(int i=1; i<=n; i++) a[i] = nextInt();
for(int i=0; i<=n; i++) f[i][0] = 1;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
//这里j-k才是前i-1盆种的花
for(int k=0; k<=a[i] && k<=j; k++){
f[i][j] = (f[i][j]+f[i-1][j-k])%mod;
}
}
}
out.println(f[n][m]);
out.flush();
out.close();
}
public static int nextInt()throws IOException{
in.nextToken();
return (int)in.nval;
}
}