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. Nodejs Express 4.X 中文API 1--- Application篇

    相关阅读: Express 4.X API 翻译[一] --  Application篇 Express4.XApi 翻译[二] --  Request篇 Express4.XApi 翻译[三] -- ...

  2. Reactor构架模式

    http://www.cnblogs.com/hzbook/archive/2012/07/19/2599698.html Reactor框架是ACE各个框架中最基础的一个框架,其他框架都或多或少地用 ...

  3. JavaScript之match()方法讲解

    定义和用法 match() 方法可在字符串内检索指定的值,或找到一个或多个正则表达式的匹配. 该方法类似 indexOf() 和 lastIndexOf(),但是它返回指定的值,而不是字符串的位置. ...

  4. Linux系统下利用wget命令把整站下载做镜像网站

    Linux系统下利用wget命令把整站下载做镜像网站 2011-05-28 18:13:01 | 1次阅读 | 评论:0 条 | itokit  在linux下完整的用wget命令整站采集网站做镜像 ...

  5. Win8必知快捷键汇总

    * Win+C:调出应用Charm菜单(开始界面.传统桌面) * Win+D:所有程序最小化,再次按下恢复(开始界面.传统桌面) * Win+E:打开我的电脑(开始界面.传统桌面) * Win+F:调 ...

  6. POJ 2142 The Balance (解不定方程,找最小值)

    这题实际解不定方程:ax+by=c只不过题目要求我们解出的x和y 满足|x|+|y|最小,当|x|+|y|相同时,满足|ax|+|by|最小.首先用扩展欧几里德,很容易得出x和y的解.一开始不妨令a& ...

  7. 大一暑假为期五周的ACM实验室培训结束了(2013.8.24)

    没想到,我的大学里第一个暑假,9周的时间只有最初的两周在家待着,接下来的7周将会在学校度过. 说真的,这是我上学以来,第一次真正好好利用的假期.在这五周里,周一.三.五下午学长都会给我们讲点知识,之后 ...

  8. POJ 2109

    #include<iostream> #include<stdio.h> #include<math.h> using namespace std; int mai ...

  9. linux下top命令查看cpu占用情况

    可以通过 top 命令来查看 CPU 使用状况.运行 top 命令后,CPU 使用状态会以全屏的方式显示,并且会处在对话的模式 -- 用基于 top 的命令,可以控制显示方式等等.退出 top 的命令 ...

  10. 51Nod 算法马拉松15 记一次悲壮而又开心的骗分比赛

    OwO 故事的起源大概是zcg前天发现51Nod晚上有场马拉松,然后他就很开心的过去打了 神奇的故事就开始了: 晚上的时候我当时貌似正在写线段树?然后看见zcg一脸激动告诉我第一题有九个点直接输出B就 ...