hduoj1677

来源:互联网 发布:录音人声放大软件 编辑:程序博客网 时间:2024/05/17 08:01

Nested Dolls

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3666    Accepted Submission(s): 1105


Problem Description
Dilworth is the world’s most prominent collector of Russian nested dolls: he literally has thousands of them! You know, the wooden hollow dolls of different sizes of which the smallest doll is contained in the second smallest, and this doll is in turn contained in the next one and so forth. One day he wonders if there is another way of nesting them so he will end up with fewer nested dolls? After all, that would make his collection even more magnificent! He unpacks each nested doll and measures the width and height of each contained doll. A doll with width w1 and height h1 will fit in another doll of width w2 and height h2 if and only if w1 < w2 and h1 < h2. Can you help him calculate the smallest number of nested dolls possible to assemble from his massive list of measurements?
 

Input
On the first line of input is a single positive integer 1 <= t <= 20 specifying the number of test cases to follow. Each test case begins with a positive integer 1 <= m <= 20000 on a line of itself telling the number of dolls in the test case. Next follow 2m positive integers w1, h1,w2, h2, . . . ,wm, hm, where wi is the width and hi is the height of doll number i. 1 <= wi, hi <= 10000 for all i.
 

Output
For each test case there should be one line of output containing the minimum number of nested dolls possible.
 

Sample Input
4320 30 40 50 30 40420 30 10 10 30 20 40 50310 30 20 20 30 10410 10 20 30 40 50 39 51
 

Sample Output
1232
题解:和hduoj1057很类似,只不过等于的时候装不进去了
#include<iostream>#include<cstdio>#include<cmath>#include<vector>#include<algorithm>#define INF 10000000+10using namespace std;int dp[20010];struct No{    int l, w;}no[20010],na[20010];bool com(No a,No b){    if(a.l == b.l)    return a.w < b.w;    return a.l > b.l;}int main(){    int t;    cin >> t;    while(t--)    {        int n,i,j;        cin >> n;        for( i = 0;i < n;i++)        {            cin >> no[i].l >> no[i].w;             na[i].l = na[i].w = 11000;        }        sort(no,no+n,com);        int ans = 0;        for(i = 0;i < n;i++)        {         j = 0;         while(na[j].l <= no[i].l|| na[j].w <= no[i].w) j++;         na[j].l = no[i].l;         na[j].w = no[i].w;           }  for(i = 0;i < n;i++)  if(na[i].l != 11000)  ans++;        cout << ans << endl;    }    return 0;
}
0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 小米云存储空间已经满怎么办 苹果手机云备份空间不足怎么办 办信用卡不知道公司电话怎么办 办信用卡不知道单位电话怎么办 朋友沉迷网络游戏怎么办英文作文 平板的密码忘了怎么办 白泥面膜过期了怎么办 小米手机桌面短信图标不见了怎么办 亚马逊账号注册扣款不成功怎么办 流量卡不用了怎么办啊 移动卡不想要了怎么办 b站调用速度过快怎么办 苹果系统占用19g怎么办 id被锁定了忘记密码怎么办 360儿童卫士忘记密码怎么办 微信注册忘记密码怎么办 旅行青蛙换手机iphone怎么办 网页邮箱添加不了附件怎么办 pos机密码忘了怎么办 在4楼上课地震了怎么办 微鲸电视待机打不开怎么办 苹果手机微信听不到语音怎么办 电信怎么办腾讯频看电视不要流量 孩子做事效率低怎么办教案 孩子做事效率低怎么办读后感 做事效率低总是焦虑怎么办 红米手机黑屏打不开怎么办 手机萤石云视频下载打不开怎么办 oppo打开网页视频慢怎么办? 晒课显示待提交怎么办 华为手机无法访问移动网络怎么办 晒课上传课堂实录太大怎么办 手机酷狗音乐下载要钱怎么办 手机酷狗下载要钱怎么办 酷我音乐没有声音怎么办 手机酷我音乐没有声音怎么办 酷我音乐歌曲下载收费怎么办 网易云下载超过每日上限怎么办 全民k歌领不了花怎么办 安卓全民k歌延迟怎么办 全民k歌唱歌延迟怎么办