UVa 10154 - Weights and Measures


I know, up on top you are seeing great sights, 

But down at the bottom, we, too, should have rights. 

We turtles can't stand it. Our shells will all crack! 

Besides, we need food. We are starving!" groaned Mack.

The Problem

Mack, in an effort to avoid being cracked, has enlisted your advice as to the order in which turtles should be dispatched to form Yertle's throne. Each of the five thousand, six hundred and seven turtles ordered by Yertle has a different weight and strength.
Your task is to build the largest stack of turtles possible.

Standard input consists of several lines, each containing a pair of integers separated by one or more space characters, specifying the weight and strength of a turtle. The weight of the turtle is in grams. The strength, also in grams, is the turtle's overall
carrying capacity, including its own weight. That is, a turtle weighing 300g with a strength of 1000g could carry 700g of turtles on its back. There are at most 5,607 turtles.

Your output is a single integer indicating the maximum number of turtles that can be stacked without exceeding the strength of any one.

Sample Input

300 1000
1000 1200
200 600
100 101

Sample Output

3

迷失在幽谷中的鸟儿,独自飞翔在这偌大的天地间,却不知自己该飞往何方……

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define INF 0x3f3f3f3f
using namespace std;
int f[6000];
struct ab
{
int w,s;
} a[6000];
bool cmp(ab a,ab b)
{
return a.s<b.s;
}
int main()
{
int N=0;
for(; ~scanf("%d%d",&a[N].w,&a[N].s); N++);
sort(a,a+N,cmp);
int M=0,i,j;
memset(f,INF,sizeof(f));
f[0]=0;
for(i=0; i<N; i++)
for(j=M; j>=0; j--)
{
if(a[i].s>=f[j]+a[i].w&&f[j]+a[i].w<f[j+1])
{
f[j+1]=f[j]+a[i].w;
if(j+1>M) M=j+1;
}
}
printf("%d\n",M);
return 0;
}

UVa 10154 - Weights and Measures的更多相关文章

  1. uva 10154 - Weights and Measures【dp】qi

    题意:uva 10154 - Weights and Measures 题意:有一些乌龟有一定的体重和力量,求摞起来的最大高度.力量必须承受其上面包含自己的所有的重量. 分析:先按其能举起来的力量从小 ...

  2. uva 10154 贪心+dp

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  3. uva 10154

    dp  记忆化搜索 做的时候像dfs  #include <iostream> #include <cstring> #include <cstdio> #incl ...

  4. UVA10154 Weights and Measures

    https://vjudge.net/problem/UVA-10154 ↑Vjudge大法好 堆一个乌龟塔.每只乌龟有重量w和承重能力s(也要承受自己的重量,所以实际可托起s-w),问最多能堆几只乌 ...

  5. Weights and Measures (贪心+dp)

    I know, up on top you are seeing great sights, But down at the bottom, we, too, should have rights. ...

  6. UVA题目分类

    题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...

  7. (Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO

    http://www.cnblogs.com/sxiszero/p/3618737.html 下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年 ...

  8. ACM训练计划step 1 [非原创]

    (Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO 下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成 ...

  9. 算法竞赛入门经典+挑战编程+USACO

    下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成.打牢基础,厚积薄发. 一.UVaOJ http://uva.onlinej ...

随机推荐

  1. UML序列图总结

    转载请注明出处:htt://blog.csdn.net/tianhai110 序列图主要用于展示对象之间交互的顺序. 序列图将交互关系表示为一个二维图.纵向是时间轴,时间沿竖线向下延伸.横向轴代表了在 ...

  2. 【BZOJ】【1986】【USACO 2004 Dec】/【POJ】【2373】划区灌溉

    DP/单调队列优化 首先不考虑奶牛的喜欢区间,dp方程当然是比较显然的:$ f[i]=min(f[k])+1,i-2*b \leq k \leq i-2*a $  当然这里的$i$和$k$都是偶数啦~ ...

  3. [工作积累] jboolean is neither JNI_TRUE nor JNI_FALSE

    jboolean result = env->CallBooleanMethod(ShopDataAndroid.IAPBridge_Object, ShopDataAndroid.IAPBri ...

  4. 火狐和IE之间的7个JavaScript差异

    尽管 JavaScript 历史上使用冗长而令人生厌的代码块来标的特定浏览器的时期已经结束了,但是偶尔使用一些简单的代码块和对象检测来确保一些代码在用户机器上正常工作依然是必要的. 这篇文章中,我会略 ...

  5. SQL TRY CATCH

    begin try select 1/0end trybegin catch select error_number() as 'number', error_line() as 'line', er ...

  6. HDU4782 Beautiful Soup

    成都赛里的一道坑爹码力题,突然间脑抽想做一下弥补一下当时的遗憾.当时没做出这道题一是因为当时只剩大概45分钟,对于这样的具有各种条件的题无从下手,二则是因为当时估算着已经有银牌了,所以就不挣扎了.但是 ...

  7. UITbaleView上按钮的单选

    设置Id属性,标记是哪个cell @property (nonatomic,assign)NSInteger Id; 设置一个普通状态和选中状态图片不同的按钮 _choose = [[UIButton ...

  8. 刘汝佳 算法竞赛-入门经典 第二部分 算法篇 第五章 3(Sorting/Searching)

    第一题:340 - Master-Mind Hints UVA:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Item ...

  9. HDU 1385 Minimum Transport Cost (Dijstra 最短路)

    Minimum Transport Cost http://acm.hdu.edu.cn/showproblem.php?pid=1385 Problem Description These are ...

  10. php怎么获取checkbox复选框的内容?

    由于checkbox属性,所有必须把checkbox复选择框的名字设置为一个如果checkbox[],php才能读取,以数据形式,否则不能正确的读取checkbox复选框的值哦. <form n ...