摆花
#include <cstdio>
#include <iostream>
using namespace std;
const int MOD = 1000007;
int n, m, a[105], f[105][105];
int dfs(int x, int y) {
if (f[x][y]) return f[x][y];
if (y == 0) {
f[x][y] = 1;
}
else if (y < 0) {
f[x][y] = 0;
}
else if (x == 0) {
f[x][y] = 0;
}
else {
for (int i = 0; i <= y && i <= a[x]; i ++) {
f[x][y] = (f[x][y] + dfs(x - 1, y - i)) % MOD;
}
}
return f[x][y];
}
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i ++) cin >> a[i];
cout << dfs(n, m);
return 0;
}
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000007;
int n, m;
int f[109][109];
int main() {
cin >> n >> m;
for (int i = 0; i <= n; i ++) f[i][0] = 1;
for (int i = 1; i <= n; i ++) {
int a;
cin >> a;
for (int j = 1; j <= m; j ++) {
for (int k = 0; k <= j && k <= a; k ++) {
f[i][j] = (f[i][j] + f[i - 1][j - k]) % MOD;
}
}
}
cout << f[n][m];
return 0;
}
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000007;
int n, m;
int f[109];
int main() {
cin >> n >> m;
f[0] = 1;
for (int i = 1; i <= n; i ++) {
int a;
cin >> a;
for (int j = m; j >= 1; j --) {
for (int k = 1; k <= j && k <= a; k ++) {
f[j] = (f[j] + f[j - k]) % MOD;
}
}
}
cout << f[m];
return 0;
}
|