题目大意:

给出N个捆包,每个捆包有相应的长度和宽度,要求堆叠捆包,使下方的捆包长宽永远大于上方的捆包的长宽。

Input

Multiple test case. For each case:

* Line 1: A single integer, N

* Lines 2..N+1: Each line describes a bale with two space-separated integers, respectively the width and breadth

Output

For each case, output one line: The height of the tallest possible tower that can legally be built from the bales.

Sample Input

6
6 9
10 12
9 11
8 10
7 8
5 3

Sample Output

5

方法一

先结构体sort()对长排序 长相等时对宽排序, 再枚举各个宽为底,算出所有可能结果,再求出最大结果

#include <bits/stdc++.h>
using namespace std;
int n,ans;
struct BALE
{
int x,y;
}bale[];
bool cmp(struct BALE q,struct BALE p)
{
if(q.x==p.x) return q.y<p.x;
return q.x>p.x;
}
void cnt(int i,int sum)
{
ans=max(ans,sum);
if(sum==n) return;
for(int j=i+;j<n;j++)
if(bale[i].y>=bale[j].y)
{
cnt(j,sum+);
if(sum==n) return;
}
}
int main()
{
while(~scanf("%d",&n))
{
ans=;
for(int i=;i<n;i++)
scanf("%d%d",&bale[i].x,&bale[i].y);
sort(bale,bale+n,cmp);
for(int i=;i<n;i++)
{
cnt(i,);
//printf("%d\n",cnt(i));
}
printf("%d\n",ans);
} return ;
}

—— 01.28更 ——

OJ测试数据更新了之后 这份代码狗带了 因为相同的情况是不能考虑的 

如:

3

9  3

8  4

8  4

答案应为  1

按方法二补

#include <bits/stdc++.h>
using namespace std;
int n,ans,flag[];
struct BALE
{
int x,y;
}bale[];
void DFS(int i,int sum)
{
ans=max(sum,ans);
if(sum==n) return;
for(int j=;j<=n;j++)
{
if(bale[i].x>bale[j].x&&bale[i].y>bale[j].y&&!flag[j])
{
flag[j]=;
DFS(j,sum+);
flag[j]=;
}
}
}
int main()
{
while(~scanf("%d",&n))
{
ans=;
for(int i=;i<=n;i++)
scanf("%d%d",&bale[i].x,&bale[i].y);
for(int i=;i<=n;i++)
{
memset(flag,,sizeof(flag));
flag[i]=;
DFS(i,);
}
printf("%d\n",ans);
} return ;
}

————————

方法二

DFS深搜  (偷下LXH的代码)

还是需要添加标记

最新文章

  1. sass/less/stylus css编译
  2. ios线程和GCD
  3. 基于UDP协议的程序设计
  4. C++面向对象基础知识
  5. 【BZOJ】2563: 阿狸和桃子的游戏
  6. Oracle逻辑读详解
  7. 图片生成操作属性导致WP内存溢出解决办法
  8. hdu1466 计算直线的交点数
  9. Tiptop二二次开发系列
  10. 扫雷游戏制作过程(C#描述):第二节、界面设计
  11. JS:onmouseover 、onmouseout
  12. Linux 磁盘分区,文件系统创建、挂载、开机自动挂载和卸载
  13. ES5 map循环一大坑:循环遍历竟然出现逗号!
  14. 完整的Django入门指南学习笔记7 网页自动翻译
  15. WordPress基础:极简手动安装教程
  16. iOS 第三方框架-Masonry
  17. [android] 手机卫士号码归属地查询
  18. Sr Software Engineer - Big Data Team
  19. 7.MQTT网页客户端连接MQTT服务器的问题WebSocket connection to &#39;ws://XXX:1883/&#39; failed: Connection closed before receiving a handshake response
  20. 926. Flip String to Monotone Increasing

热门文章

  1. git的使用(本地版本库)
  2. ActiveX (ocx) 控件 在vs2010 上debug 的方法
  3. jmeter 响应超时时间设置 压力增大,不能正常退出全部线程
  4. [轉]关于CR0.WP
  5. 初探remoting双向通信(一)
  6. 函数高阶(函数,改变函数this指向,高阶函数,闭包,递归)
  7. (转)Http和Https的区别
  8. centos7 实测 nagios 安装
  9. 杭电多校第四场-H- K-th Closest Distance
  10. 【模板篇】NTT和三模数NTT