HDOJ2546
来源:互联网 发布:阿里云最便宜的服务器 编辑:程序博客网 时间:2024/06/04 19:26
#include <iostream> #include <cstring> #include <string> #include <cstdio> #include <algorithm> #include <stack> #include <math.h> #include<iostream> #include <map> using namespace std;#define INF 0xfffff;//0x代表十六进制 #define M 1050 int a[M],dp[M];int main(){int n, m;while (cin >> n,n){memset(dp, 0, sizeof(dp));for (int i = 1; i <= n; i++) cin >> a[i];cin >> m;sort(a+1, a + n+1);if (m >= 5){m -= 5;for (int i = n - 1; i >= 1; i--)for (int j = m; j >= a[i]; j--) dp[j] = max(dp[j], dp[j - a[i]] + a[i]);cout << m - dp[m]+5- a[n] << endl; //5块买最贵的 剩下的买剩下的}else cout << m << endl;}return 0;}
阅读全文
0 0
- HDOJ2546
- HDOJ2546 饭卡
- hdoj2546 饭卡
- hdoj2546饭卡
- 饭卡hdoj2546
- 饭卡(HDOJ2546)
- hdoj2546饭卡(背包01)
- HDOJ2546 饭卡(0/1背包)
- 01背包 加 贪心 HDOJ2546饭卡
- 深度学习与神经网络-吴恩达(Part1Week2)-Logistic Regression编程实现(python)
- Javalistener中的Session配置
- CentOs6.5安装Hive2.3.0
- STL c++
- 简述k-近邻(KNN)算法流程
- HDOJ2546
- swift阶乘求1! + 2! + 3! + 4!的和方法
- Android设置View的margin
- rails 如何使用https get post json 运用的办法
- 17/10/20题目泛做
- 机器学习Chapter3-(聚类分析)Python实现K-Means算法
- 在 VS2015 中使用 Qt4
- Joystick 虚拟操纵杆
- angular的添加,模糊查询,年龄区间查询,投票