WA #2 #5 #6 #7 #8 #10
查看原帖
WA #2 #5 #6 #7 #8 #10
1053722
yu_rui楼主2025/6/19 12:05

R220794804 记录详情

#include<bits/stdc++.h>
using namespace std;
int a[1001],b[10001];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,w;
    cin>>n>>w;
    for(int i=1;i<=n;++i) cin>>a[i];
    for(int i=1;i<=w;++i){
        b[i]=INT_MAX;
        for(int j=1;j<=n;++j){
            if(i-a[j]>=0) b[i]=min(b[i],b[i-a[j]]+1);
        }
    }
    cout<<b[w];
    return 0;
}
2025/6/19 12:05
加载中...