首页 > 其他 > 详细

ch_5201 数字组合

时间:2019-11-06 16:39:50      阅读:100      评论:0      收藏:0      [点我收藏+]

01背包

#include<iostream>
#include<cstdio>

#define ri register int
#define u int

namespace opt {

    inline u in() {
        u x(0),f(1);
        char s(getchar());
        while(s<0||s>9) {
            if(s==-) f=-1;
            s=getchar();
        }
        while(s>=0&&s<=9) {
            x=(x<<1)+(x<<3)+s-0;
            s=getchar();
        }
        return x*f;
    }

}

using opt::in;

#define NN 105
#define MM 10005

#include<algorithm>

namespace mainstay {

    u N,M,a[NN],f[MM]={1};

    inline void solve() {
        std::cin>>N>>M;
        for(ri i(1);i<=N;++i) std::cin>>a[i];
        for(ri i(1);i<=N;++i){
            for(ri j(M);j>=a[i];--j){
                f[j]+=f[j-a[i]];
            }
        }
        std::cout<<f[M];
    }

}

int main() {

    //freopen("x.txt","r",stdin);
    std::ios::sync_with_stdio(false);
    mainstay::solve();

}

 

ch_5201 数字组合

原文:https://www.cnblogs.com/ling-zhi/p/11805755.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!