我看不懂题解的搜索,而且我的搜索好像不可以记忆化,求点播
查看原帖
我看不懂题解的搜索,而且我的搜索好像不可以记忆化,求点播
742305
du1wu2debenben楼主2024/3/18 19:23
#include<iostream>
#include<vector>
#include<algorithm>
#define int long long
using namespace std;

int n,m;
int a[105];
const int mod=1e6+7;
int ans;
bool rmb[105][105];

void dfs(int step,int flowers){
    if(flowers>m) return;
    if(flowers==m){
        ans++; ans%=mod; return;
    }
    for(int i=step;i<=n;i++){
        for(int j=1;j<=a[i];j++){
            dfs(i+1,flowers+j);
        }
    }
    return;
}

signed main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    dfs(1,0);
    cout<<ans%mod<<endl;
    return 0;
}
2024/3/18 19:23
加载中...