0/1背包问题


    int maxx=0;
    for(int i=1;i<=res.size();i++){
        for(int j=1;j<=a;j++){
            if(res[i-1].price>j){
                dp[i][j]=dp[i-1][j];
                

            }else{//放与不放,dp[i-1][j-res[i-1].price]:放入后,在j-res[i-1].price容量的最大评价
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-res[i-1].price]+res[i-1].score);

            }
            maxx=max(dp[i][j],maxx);
        }
    }
    cout<<maxx<<endl;
    



}

}// 64 位输出请用 printf("%lld")

全部评论

相关推荐

点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务