【1248】寒冰王座

 2023-09-05 阅读 83 评论 0

摘要:1248 背包 Sample Input 2 900 250 Sample Output 0 50 #include<bits/stdc++.h> using namespace std; int dp[10005]; int h[3]={150,200,350};//是价值也是重量 ,这道题价值=重量 int main(){int t;scanf("%d",&t);int n;while(t

1248
背包

Sample Input
2
900
250

Sample Output
0
50

#include<bits/stdc++.h>
using namespace std;
int dp[10005];
int h[3]={150,200,350};//是价值也是重量 ,这道题价值=重量 
int main(){int t;scanf("%d",&t);int n;while(t--){scanf("%d",&n);memset(dp,0,sizeof(dp));for(int i=0;i<3;i++){for(int j=h[i];j<=n;j++){dp[j]=max(dp[j],dp[j-h[i]]+h[i]);}}printf("%d\n",n-dp[n]);//又因为忘记换行符WA了几次(……)下次要注意}return 0;
} 

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://808629.com/164.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 86后生记录生活 Inc. 保留所有权利。

底部版权信息