/* 感觉可以用动规是要靠刷题的
初始状态,中间转移,末尾决策
几个for循环就结束了
状态转移方程是关键看题目而定
只要是符合题目状态并且处理好了
初始条件状态是对的
基本就对的*/
#include <iostream>
using namespace std;
const int N = 1e2 + 10;
const int MOD = 1000007;
int n, m;
int a[N];
int dp[N][N];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; ++i)
{
cin >> a[i];
}
for (int i = 1; i <= a[1]; ++i)
dp[1][i] = 1;
for (int i = 1; i <= n; ++i)
dp[i][0] = 1;
for (int i = 2; i <= n; ++i)
{
for (int j = 1; j <= m; ++j)
{
for (int k = 0; k <= a[i] && k <= j; ++k)
{
dp[i][j] = dp[i][j] + dp[i - 1][j - k];
dp[i][j] = dp[i][j] % MOD;
}
}
}
cout << dp[n][m] << endl;
return 0;
}
动态规划(摆花)
最新推荐文章于 2024-04-04 10:13:10 发布