纸币问题3

题目传送门

整体思想:推式子DP

死因:数组开小了

代码如下

#include<bits/stdc++.h>
using namespace std;

const int N=2010;

int n,w,a[N],f[N][N*10];//可以发现我这边原本开小了,后来*10过了
const int p=1e9+7;

int main(){
	cin.tie(0)->sync_with_stdio(0);
	cin>>n>>w;
	for(int i=1;i<=n;i++) cin>>a[i];
	f[0][0]=1;
	for(int i=1;i<=n;i++){
		for(int j=0;j<=w;j++){
			f[i][j]=f[i-1][j];
			if(j>=a[i]) f[i][j]=(f[i][j]+f[i][j-a[i]])%p;
		}
	}
	cout<<f[n][w]<<endl;
}
posted @ 2026-01-24 11:43  zhangruotian_Max  阅读(1)  评论(0)    收藏  举报