HDU2546
来源:互联网 发布:淘宝客服流程 编辑:程序博客网 时间:2024/05/16 09:32
简单的01背包问题
http://acm.hdu.edu.cn/showproblem.php?pid=2546
#include "HDU2546.h"#include<iostream>#include<algorithm>using namespace std;int cmp(int a, int b){return a < b;}int main(){int n;while (scanf("%d", &n), n){int price[2013]={0};int dp[2013]={0};for(int i = 1; i <= n; i++)scanf("%d", &price[i]);sort(price + 1, price + 1 + n);int MAX = price[n];int m;scanf("%d", &m);if (m < 5){printf("%d\n",m);continue;}m -= 5;for (int i = 1; i < n; i++){for (int j = m; j >= price[i]; j--){dp[j] = max(dp[j], dp[j-price[i]] + price[i]);}}printf("%d\n", m+5-dp[m]-MAX);}return 0;}HDU2546::HDU2546(void){}HDU2546::~HDU2546(void){}
几个注意点:
1.两个数组的初始值都为零,原先把DP[],price[] 都设置成全局变量,导致了wrong answer,低级错误~~
2.对于数组下标犯错了
3. m的值刚开始没有减 5
- hdu2546
- hdu2546
- hdu2546
- hdu2546
- HDU2546
- hdu2546
- HDU2546
- HDU2546
- HDU2546
- 饭卡 hdu2546
- HDU2546 饭卡
- 【标记】hdu2546
- hdu2546-饭卡
- HDU2546:饭卡
- hdu2546 饭卡
- HDU2546 饭卡
- HDU2546 饭卡
- hdu2546 饭卡
- [转]造成segment fault,产生core dump的可能原因
- VectorCAST-自动化软件测试工具
- java 数字计算精度问题
- 初识windows编程之动态链接库
- ExtJs ButtonGroup按钮组
- HDU2546
- 斜杠与反斜杠
- 代码创建UISearchDisplayCountroller
- Oracle中job的使用详解
- Tomcat优化(心得经验)
- android ImageView scaleType属性
- 接口IIC_SPI_URAT_USB
- Eclipse 来编译Arduino程序,并烧写Arduino程序
- ios7 新特性