use fmax().-------TLE

#define mmax(a,b) (a)>(b)?(a):(b);   ---796ms

that's it!

#include <stdio.h>
#include <string.h>
#include <math.h>
#define mmax(a,b) (a)>(b)?(a):(b);
int main(){
int dp[**+];
int n,t,i,j,res;
int w[+];
int t1,t2;
int cnt,sum;
while(~scanf("%d",&n)){
if(n<=) break;
sum=;
cnt=;
memset(dp,,sizeof(dp));
for(i=;i<=n;++i){
scanf("%d%d",&t1,&t2);
sum+=t1*t2;
for(j=;j<=t2;++j){
w[++cnt]=t1;
}
}
int haha;
haha=sum/;
for(i=;i<=cnt;++i)
for(j=haha;j>=w[i];--j)
dp[j]=mmax(dp[j],dp[j-w[i]]+w[i]);
t1=;
t1=dp[haha];
t2=sum-t1; if(t1<t2){
t=t1;t1=t2;t2=t;
}
printf("%d %d\n",t1,t2);
}
return ;
}

hdu1171的更多相关文章

  1. Big Event in HDU(HDU1171)可用背包和母函数求解

    Big Event in HDU  HDU1171 就是求一个简单的背包: 题意:就是给出一系列数,求把他们尽可能分成均匀的两堆 如:2 10 1 20 1     结果是:20 10.才最均匀! 三 ...

  2. 多重背包的入门题目HDU1171,2191,2844.

    首先,什么叫多重背包呢? 大概意思就是:一个背包有V总容量,有N种物品,其价值分别为Val1,Val2--,Val3,体积对应的是Vol1,Vol2,--,Vol3,件数对应Num1,Num2--,N ...

  3. HDU1171将多个不同价值不同数量的器材尽可能按等价值均分 第一份的价值尽可能的大 所以sum/2对第二份进行01背包 使其价值尽可能的大

    //hdu1171void solve(){ for(int i=1;i<=n;i++) { for(int j=W;j>=w[i];j--) { dp[j]=max(dp[j],dp[j ...

  4. hdu1171&&P2000——母函数

    hdu1171 题意:有 $n$ 种设施,每种有价值 $v_i$ 和数量 $m_i$,求一种方案使得分成价值尽可能相近的两组.($n \leq 50, v_i \leq 50, m_i \leq 10 ...

  5. iOS-私有API与runtime

    转载:http://www.jianshu.com/p/6167b9ce7af8 序 有朋友在做类似iTool的功能,跟我聊起来,这几天闲,就写了一个demo,不是正经做这个,还很粗略,具体干货诸位等 ...

  6. HDU-1171 Big Event in HDU

    Big Event in HDU Problem Description Nowadays, we all know that Computer College is the biggest depa ...

  7. Big Event in HDU[HDU1171]

    Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  8. HDU1171——Big Event in HDU(母函数)

    Big Event in HDU DescriptionNowadays, we all know that Computer College is the biggest department in ...

  9. hdu1171 Big Event in HDU 01-背包

    转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1171 Problem ...

随机推荐

  1. Linux tar指令

    linux 下的命令真是太多了.最近在看<Linux Shell编程从初学到精通>一书.该书有468页,很可惜我并不是那种很有耐性一个例子一个例子地跟着做的人,最多在看到些不太清楚的地方会 ...

  2. iframe替代方案

    自己写一个pagelet框架.封装成JSP的Taglib. <tms:view header="common-header" footer="common-foot ...

  3. JAVA 静态成员 static

    static关键字 一.作用:是一个修饰符,用于修饰成员(成员变量,成员方法)1.被static 修饰后的成员变量只有一份2.当成员被static修饰之后,多了一种访问方式,除了可以被对象调用之外还可 ...

  4. JAVA中IO总结

    JAVA中IO流主要分为两大类: 字节流:InputStream+OutputStream 字符流:Reader+Writer 字节流: InputStream是所有字节输入流的父类 OutputSt ...

  5. java使用thrift

    maven项目添加依赖: <dependency> <groupId>org.apache.thrift</groupId> <artifactId>l ...

  6. 临时改GCC编译器,重启后失效

    临时改GCC编译器,重启后失效.例如,用如下命令: export CROSS_COMPILE= <gcc 文件所在的目录>/arm-linux-gnueabihf- 本例中使用的命令如下: ...

  7. MemoryStream 的GetBuffer() 和 ToArray()的区别

    GetBuffer(): Note that the buffer contains allocated bytes which might be unused. For example, if th ...

  8. Object的toString决定了重写equals

    默认的toString结果public String toString(){    return getClass().getName()+"@"+Integer.toHexStr ...

  9. Codeforces Round #219 (Div. 2) B. Making Sequences is Fun

    B. Making Sequences is Fun time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  10. HDU 2209 翻纸牌游戏 状态BFS

    翻纸牌游戏 Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem De ...