跳到正文

个人记录

ask1

wangsy2014约 1 分钟
原文
文章信息与版本

文章信息

收录
2026年2月5日
更新
2026年2月5日
篇幅
约 1 分钟

版本

  1. v2当前
  2. v1
C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e4+5,mod=1e9+7;
int n,m,w[N],dp[N];
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cin>>n>>m;
	dp[0]=1;
	for(int i=1;i<=n;i++)
	{
		cin>>w[i];
	}
	for(int i=1;i<=m;i++)
	{
		for(int j=1;j<=n;j++)
		{
            if(i<w[j])
            {
                continue;
            }
			dp[i]+=dp[i-w[j]];
            dp[i]%=mod;
		 }
	}
	cout<<dp[m];
	return 0;
}
/*

6 15
1 5 10 20 50 100

3 15
1 5 11

*/
原文