洛谷P1077

这道题和上一道题也是比较像的,基本采用的也是线性dp的思路
状态数组稍微有点不同,这里表示的是当前种数的花时一共的花的数量

#include<iostream>
#include<utility>
using namespace std;
typedef long long ll;
#define fi(i,a,b) for(int i = a; i <= b; ++i)
#define fr(i,a,b) for(int i = a; i >= b; --i)
#define x first
#define y second
#define sz(x) ((int)(x).size())
#define pb push_back
using pii = pair<int,int>;
//#define DEBUG
int limi[105];
int dp[105][105];
const int N = 1e6 + 7;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin >> n >> m;
    fi(i,1,n) cin >> limi[i];
    fi(i,0,limi[1]) dp[1][i] = 1;
    fi(i,2,n){
        fi(k,0,limi[i]){
            fi(j,k,m)
                {
                    dp[i][j] += dp[i-1][j - k];
                    dp[i][j] %= N;
                }
        }
    }
    cout << dp[n][m] << endl;
#ifdef DEBUG
    //freopen(D:\in.txt,r,stdin);
#endif
    return 0;
}
posted @ 2022-02-25 14:00  Sun-Wind  阅读(28)  评论(0编辑  收藏  举报