Robots
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 3621 Accepted: 1643

Description

Your company provides robots that can be used to pick up litter from fields after sporting events and concerts. Before robots are assigned to a job, an aerial photograph of the field is marked with a grid. Each location in the grid that contains garbage is marked. All robots begin in the Northwest corner and end their movement in the Southeast corner. A robot can only move in two directions, either to the East or South. Upon entering a cell that contains garbage, the robot will pick it up before proceeding. Once a robot reaches its destination at the Southeast corner it cannot be repositioned or reused. Since your expenses are directly proportional to the number of robots used for a particular job, you are interested in finding the minimum number of robots that can clean a given field. For example, consider the field map shown in Figure 1 with rows and columns numbered as shown and garbage locations marked with a 'G'. In this scheme, all robots will begin in location 1,1 and end in location 6, 7. 
 
Figure 1 - A Field Map
Figure 2 below shows two possible solutions, the second of which is preferable since it uses two robots rather than three. 
 
Figure 2 - Two Possible Solutions
Your task is to create a program that will determine the minimum number of robots needed to pick up all the garbage from a field. 

Input

The input consists of one or more field maps followed by a line containing -1 -1 to signal the end of the input data. A field map consists of one or more lines, each containing one garbage location, followed by a line containing 0 0 to signal the end of the map. Each garbage location consists of two integers, the row and column, separated by a single space. The rows and columns are numbered as shown in Figure 1. The garbage locations will be given in row-major order. No single field map will have more than 24 rows and 24 columns. The sample input below shows an input file with two field maps. The first is the field map from Figure 1.

Output

The output will consist of a single line for each field map containing the minimum number of robots needed to clean the corresponding field.

Sample Input

1 21 42 42 64 44 76 60 01 12 24 40 0-1 -1

Sample Output

21

Source

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
struct Node
{
    int x,y;
}p[10000];
bool cmp(Node a,Node b)
{
    if(a.x!=b.x)
    {
        return a.x>b.x;
    }
    else
    {
        return a.y>b.y;
    }
}
int main()
{
    int n=0;
    int a,b;
    while(cin>>a>>b)
    {
        if(a==-1&&b==-1) break;
        if(a==0&&b==0)
        {
            sort(p,p+n,cmp);
            int dp[10000];
            for(int i=0;i<n;i++)
            {
                dp=1;
                for(int j=0;j<i;j++)
                {
                    if(p[j].y<p.y&&dp<dp[j]+1)
                    {
                        dp=dp[j]+1;
                    }
                }
            }
            int ans=-1;
            for(int i=0;i<n;i++)
            {
                ans=max(ans,dp);
            }
            cout<<ans<<endl;
            n=0;
            continue;
        }
        p[n].x=a;
        p[n].y=b;
        n++;
    }
    return 0;
}

POJ 1548 Robots (Dilworth)的更多相关文章

  1. POJ 1548 Robots(最小路径覆盖)

    POJ 1548 Robots 题目链接 题意:乍一看还以为是小白上那题dp,事实上不是,就是求一共几个机器人能够覆盖全部路径 思路:最小路径覆盖问题.一个点假设在还有一个点右下方,就建边.然后跑最小 ...

  2. POJ 1548 (二分图+最小路径覆盖)

    题目链接:http://poj.org/problem?id=1548 题目大意:给出一张地图上的垃圾,以及一堆机器人.每个机器人可以从左->右,上->下.走完就废.问最少派出多少个机器人 ...

  3. poj 1548(最小路径覆盖)

    题目链接:http://poj.org/problem?id=1548 思路:最小路径覆盖是很容易想到的(本题就是求最小的路径条数覆盖所有的点),关键是如何建图,其实也不难想到,对于当前点,如果后面的 ...

  4. 【转载】图论 500题——主要为hdu/poj/zoj

    转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

  5. hdu图论题目分类

    =============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...

  6. HDU图论题单

    =============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...

  7. 模拟 POJ 2632 Crashing Robots

    题目地址:http://poj.org/problem?id=2632 /* 题意:几个机器人按照指示,逐个朝某个(指定)方向的直走,如果走过的路上有机器人则输出谁撞到:如果走出界了,输出谁出界 如果 ...

  8. Poj OpenJudge 百练 2632 Crashing Robots

    1.Link: http://poj.org/problem?id=2632 http://bailian.openjudge.cn/practice/2632/ 2.Content: Crashin ...

  9. POJ 2632 Crashing Robots(较为繁琐的模拟)

    题目链接:http://poj.org/problem?id=2632 题目大意:题意简单,N个机器人在一个A*B的网格上运动,告诉你机器人的起始位置和对它的具体操作,输出结果: 1.Robot i ...

随机推荐

  1. Android EditText 不弹出输入法

    当第一次进入一个activity的时候  一般是第一个edittext是默认选中的,但是该死的软键盘也一起弹出来了 那是相当的不美观哈!(#‵′)凸.为此, 本大人就去寻找在刚进入这个activity ...

  2. 国际制造执行系统(MES)应用与发展

    某些专家认为,当今制造业的生存三要素是信息技术(IT).供应链管理(SCM)和成批制造技术.使用信息技术就是由依赖人工的作业方式转变为作业的快速化.高效化,大量减少人工介入,降低生产经营成本:供应链管 ...

  3. ASP.NET中前台调用后台的方法

    学习文章:http://www.cnblogs.com/kingteach/archive/2010/11/12/1875633.html 练习代码: 前台: <html xmlns=" ...

  4. STM32F4_TIM输入波形捕获(脉冲频率)

    Ⅰ.概述 本文在前面文章“STM32基本的计数原理”的基础上进行拓展,讲述关于“定时器输入捕获”的功能,和上一篇文章“定时器比较输出”区别还是挺大的.在引脚上刚好相反:一个输入.一个输出. 本文只使用 ...

  5. iPhone图标及启动画面大小 xcode5

    启动画面 文件名   大小px Default.png 320*480 Default@2x.png 640*960 Default-568h@2x.png 640*1136 图标 文件名  大小px ...

  6. 【微网站开发】之微信内置浏览器API使用

    最近在写微网站,发现了微信内置浏览器的很多不称心的地方: 1.安卓版的微信内浏览器底部总是出现一个刷新.前进.后退的底部栏,宽度很大,导致屏幕显示尺寸被压缩 2.分享当前网站至朋友圈时,分享的图片一般 ...

  7. 菜鸟学习SSH——目录

    菜鸟学习Struts--配置Struts环境 菜鸟学习Struts--简易计算器 菜鸟学习Struts--bean标签库 菜鸟学习Struts--Scope属性 菜鸟学习Struts--国际化 菜鸟学 ...

  8. Media Player(APP)

    今天共享一下,以前做的影音播放器.比较简单.适合新手. 我上传了附件可以参考一下. PDF:http://files.cnblogs.com/files/hongguang-kim/MediaPlay ...

  9. SQL Server实现数据的递归查询

    在一次项目中遇到一种需求,需要记录某产品的替换记录. 实际应用举例为:产品101被201替换,之后201又被303替换,303又被109替换:产品102被202替换,之后202又被105替换. 现在我 ...

  10. scjp考试准备 - 7 - Java构造器

    题目——如下代码的执行结果: class Hello{ String title; int value; public Hello(){ title += " World!"; } ...