先排序,再动态规划。须要优化

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<map>
#include<algorithm> using namespace std; const int maxn = 1e3+10;
const int maxm = 1e6+10;
int a[maxn];
int f[maxm]; int main()
{
int N, k, i, j, m;
while(scanf("%d", &N)!=EOF)
{
memset(f, 0, sizeof(f)); for(i = 0; i < N; i ++)
scanf("%d", &a[i]);
sort(a, a+N);
m = 0;
f[0] = 1;
k = 1; //K是不能组合的最小值。即临时的答案
for(i = 0; i < N; i ++)
{
m += a[i]; //前i个数之和,组合的最大值
if(k < a[i]) break; //假设此时的a[i]已经比K值大了。那么就再不可以组合得到K了,K即终于答案了
for(int j = m; j >= k; j --)
{
if(f[j-a[i]] == 1) f[j] = 1;
}
while(f[k] == 1) k ++; }
printf("%d\n", k);
} return 0;
}

hdu 4104的更多相关文章

  1. HDU 4104 Discount(n个数不能构成的最小值)

    http://acm.hdu.edu.cn/showproblem.php?pid=4104 题意:给出n个数,每个数最多只能用一次,每次可以选任意个数相加,求不能相加得到的最小值是多少. 思路: 先 ...

  2. hdu 4104 Discount

    http://acm.hdu.edu.cn/showproblem.php?pid=4104 一开始还以为这题是背包,然后优化下这个背包,但是一直都优化不出来. 然后题解是直接模拟而已,唉 先从小到大 ...

  3. HDU 3336 Count the string(KMP的Next数组应用+DP)

    Count the string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  4. HDU 5643 King's Game 打表

    King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...

  5. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  6. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  7. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  8. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  9. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

随机推荐

  1. The only legal comparisons are between two numbers, two strings, or two dates.

    The only legal comparisons are between two numbers, two strings, or two dates. Left  hand operand is ...

  2. bzoj1003: [ZJOI2006]物流运输

    dp+最短路.暴力枚举就可以了.O(n3logn).样例中m=n然后测样例过了.然后 54行习惯性的dis[n]然后就WA了!!!. #include<cstdio> #include&l ...

  3. 解决angular的post请求后SpringMVC后台接收不到参数值问题的方法

    这是我后台SpringMVC控制器接收isform参数的方法,只是简单的打出它的值: @RequestMapping(method = RequestMethod.POST) @ResponseBod ...

  4. 嵌入式Linux系统运行流程图

    /************************************************************************ * 嵌入式Linux系统运行流程图 * 说明: * ...

  5. 【转】JNI和NDK的区别

    原文网址:http://blog.csdn.net/ithomer/article/details/6828830 NDK(Native Development Kit)“原生”也就是二进制 andr ...

  6. Spring AOP--返回通知,异常通知和环绕通知

    在上篇文章中学习了Spring AOP,并学习了前置通知和后置通知.地址为:http://www.cnblogs.com/dreamfree/p/4095858.html 在本文中,将继续上篇的学习, ...

  7. Jquery AutoComplete的使用方法实例

    jquery.autocomplete详解 语法: autocomplete(urlor data, [options] ) 参数: url or data:数组或者url [options]:可选项 ...

  8. ADO.NET - 全面梳理

    转自:http://www.cnblogs.com/yangcaogui/archive/2012/06/09/2537086.html 目录: 简单的介绍下ADO.NET SqlConnection ...

  9. HDU 1074 Doing Homework 状压DP

    由于数据量较小,直接二进制模拟全排列过程,进行DP,思路由kuangbin blog得到,膜拜斌神 #include<iostream> #include<cstdio> #i ...

  10. 不区分大小写匹配字符串,并在不改变被匹配字符串的前提下添加html标签

    问题描述:最近在搭建一个开源平台网站,在做一个简单搜索的功能,需要将搜索到的结果中被匹配的字符串添加不一样的颜色,但是又不破坏被匹配的字符串. 使用的方法是替换被匹配的字符串加上font标签.但是搜索 ...