Wooden Sticks
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 16262 Accepted: 6748

Description

There is a pile of n wooden sticks. The length and weight of each stick are known in advance. The sticks are to be processed by a woodworking machine in one by one fashion. It needs some time, called setup time, for the machine to prepare processing a stick. The setup times are associated with cleaning operations and changing tools and shapes in the machine. The setup times of the woodworking machine are given as follows: 
(a) The setup time for the first wooden stick is 1 minute. 
(b) Right after processing a stick of length l and weight w , the machine will need no setup time for a stick of length l' and weight w' if l <= l' and w <= w'. Otherwise, it will need 1 minute for setup. 
You are to find the minimum setup time to process a given pile of n wooden sticks. For example, if you have five sticks whose pairs of length and weight are ( 9 , 4 ) , ( 2 , 5 ) , ( 1 , 2 ) , ( 5 , 3 ) , and ( 4 , 1 ) , then the minimum setup time should be 2 minutes since there is a sequence of pairs ( 4 , 1 ) , ( 5 , 3 ) , ( 9 , 4 ) , ( 1 , 2 ) , ( 2 , 5 ) .

Input

The input consists of T test cases. The number of test cases (T) is given in the first line of the input file. Each test case consists of two lines: The first line has an integer n , 1 <= n <= 5000 , that represents the number of wooden sticks in the test case, and the second line contains 2n positive integers l1 , w1 , l2 , w2 ,..., ln , wn , each of magnitude at most 10000 , where li and wi are the length and weight of the i th wooden stick, respectively. The 2n integers are delimited by one or more spaces.

Output

The output should contain the minimum setup time in minutes, one per line.

Sample Input

3
5
4 9 5 2 2 1 3 5 1 4
3
2 2 1 1 2 2
3
1 3 2 2 3 1

Sample Output

2
1
3

Source

#include <iostream>

#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
struct Node
{
    int l;
    int w;
    int id;
}p[5555];
bool cmp(Node x,Node y)
{
    if(x.l!=y.l)
    {
        return x.l<y.l;
    }
    else
    {
        return x.w<y.w;
    }
}
int main()
{
    int T;
    cin>>T;
while(T--)
{
    memset(p,0,sizeof(p));
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>p.l>>p.w;
        p.id=i;
    }
    sort(p,p+n,cmp);
    int dp[5555];
    for(int i=0;i<n;i++)
    {
        dp=1;
        for(int j=0;j<i;j++)
        {
            if(p.w<p[j].w)
            {
                if(dp<dp[j]+1)
                {
                    dp=dp[j]+1;
                }
            }
        }
    }
    int maxn=-1;
    for(int i=0;i<n;i++)
    {
//        cout<<p.id<<" ";
        maxn=max(maxn,dp);
    }
//    cout<<endl;
    cout<<maxn<<endl;
}
    return 0;
}

POJ 1065 Wooden Sticks的更多相关文章

  1. HDU ACM 1051/ POJ 1065 Wooden Sticks

    Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  2. POJ 1065 Wooden Sticks / hdu 1257 最少拦截系统 DP 贪心

    参考链接:http://blog.csdn.net/xiaohuan1991/article/details/6956629 (HDU 1257 解题思路一样就不继续讲解) POJ 1065题意:给你 ...

  3. POJ 1065 Wooden Sticks (贪心)

    There is a pile of n wooden sticks. The length and weight of each stick are known in advance. The st ...

  4. poj -1065 Wooden Sticks (贪心or dp)

    http://poj.org/problem?id=1065 题意比较简单,有n跟木棍,事先知道每根木棍的长度和宽度,这些木棍需要送去加工,第一根木棍需要一分钟的生产时间,如果当前木棍的长度跟宽度 都 ...

  5. poj 1065 Wooden Sticks 【贪心 新思维】

    题目地址:http://poj.org/problem?id=1065 Sample Input 3 5 4 9 5 2 2 1 3 5 1 4 3 2 2 1 1 2 2 3 1 3 2 2 3 1 ...

  6. POJ 1065 Wooden Sticks(zoj 1025) 最长单调子序列

    POJ :http://poj.org/problem?id=1065 ZOJ: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId= ...

  7. POJ 1065 Wooden Sticks【贪心】

    题意: 有一些木棍,每个有长度和重量,要求把这些木棍排成若干两个属性值均不下降的序列.问至少要分为多少个序列.且要保证排出来的子序列数最少. 思路: ( 9 , 4 ) ,( 2 , 5 ) ,( 1 ...

  8. POJ 1065 Wooden Sticks Greed,DP

    排序后贪心或根据第二关键字找最长下降子序列 #pragma comment(linker, "/STACK:1024000000,1024000000") #include< ...

  9. POJ 1065 Wooden Sticks#贪心+qsort用法

    (- ̄▽ ̄)-* 这道题用到了cstdlib库的qsort()函数: 用法链接:http://www.cnblogs.com/syxchina/archive/2010/07/29/2197382.h ...

随机推荐

  1. 信驰达蓝牙4.0模块全面升级 v2.20 U最新发布

    作为国际蓝牙联盟成员之一,德州仪器(TI)于2012年强势推出CC254X系列单芯片(SOC)低功耗蓝牙收发器,经典51内核,最强优势在于丰富的外围(21个IO,UART,SPI,USB2.0,PWM ...

  2. USB总线介绍

    •USB 1.0出现在1996年的,速度只有1.5Mb/s1998年升级为USB 1.1,速度也提升到12Mb/s,称之为”full speed” •USB2.0规范是由USB1.1规范演变而来的.它 ...

  3. 实战Django:官方实例Part2

    我们接着Part1部分往下讲.我们在part1中启动服务器后,并没有在管理页面中发现新添加的Polls应用,怎么办捏? 7.在管理界面中显示Question 只要注册一下这个应用就可以了.编辑poll ...

  4. C开发 中原子性操作 , 除了快什么都不剩下了

    题外话 今天,听歌曲听到一首缅怀迈克尔·杰克逊的歌曲 如下: http://music.163.com/#/song?id=1696048  Breaking News 每次听迈克尔 音乐,特别有战斗 ...

  5. [转]Oracle 10g及pro*c相关问题及解决方法(转)

    Oracle 10g及pro*c相关问题及解决方法 2008年08月21日 星期四 上午 11:21 最近一直在进行ORACLE 10g和PRO*C的学习. 其中遇到了不少的问题: 现列于此,已备他用 ...

  6. OracleINSERT提示IGNORE_ROW_ON_DUPKEY_INDEX

    OracleINSERT提示IGNORE_ROW_ON_DUPKEY_INDEX insert提示IGNORE_ROW_ON_DUPKEY_INDEX 在 insert into table a() ...

  7. 菜鸟学习Hibernate——简单的一个例子

    一.Hibernate开发. 上篇博客已经为大家介绍了持久层框架的发展流程,持久层框架的种类. 为了能够使用Hibernate快速上手,我们先讲解一个简单的Hibernate应用实例hibernate ...

  8. IIS 配置错误解决方法集合

    问题:405 - 不允许用于访问此页的 HTTP 谓词 解决:IIS处理程序映射中添加模块映射,模块选择:ServerSideIncludeModule,名称:SSINC-HTML

  9. oracle group 语句探究(笔记)

    1.group by语句在oracle中没有排序功能,必须依靠order by才能实现按照预定结果的排序 2.group by 的cube扩展 with test as ( id, name from ...

  10. 我爱我家:我为什么选择AppCan?

    10年前,说起手机,大家联想到的词大概是:电话.短信.QQ.拍照,以及贪吃蛇等有限的几个小游戏.而如今,手机毫无疑问已经成为人们生活中不可或缺的部分.这是一个神奇的东西:通讯工具,外卖神器,游戏机,移 ...