P1077 [NOIP2012 普及组] 摆花
本博客给出本题截图:
AC代码
代码解释:f[i][j]
代表摆了第i
种花后,已经摆了j
盆的最优解,本题注意初始化f
数组,摆了i
种花,已经摆了0
盆的方案数显然是1
代码*:
#include <iostream> using namespace std; const int N = 110, mol = 1e6 + 7; int f[N][N]; int n, m; int a[N]; int main() { cin >> n >> m; for (int i = 1; i <= n; i ++ ) cin >> a[i]; 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 ++ ) for (int k = j; k >= max(j - a[i], 0); k -- ) f[i][j] = (f[i][j] + f[i - 1][k]) % mol; cout << f[n][m] << endl; return 0; }