http://poj.org/problem?id=1065

题意比较简单,有n跟木棍,事先知道每根木棍的长度和宽度,这些木棍需要送去加工,第一根木棍需要一分钟的生产时间,如果当前木棍的长度跟宽度

都大于前一根木棍,那么这根木棍不需要生产时间,问你最少的生产时间是多少?

首先可以贪心,先按长度 l排序,如果l相同,按宽度w排序。

从i=0开始,每次把接下来的i+1  -  n-1 的没有标记并且长度和宽度大于等于i这根木棍的长度和宽度标记起来。

 #include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn = ; struct point
{
int l,w;
bool operator < (const point &a) const
{
return l==a.l ? w<a.w : l<a.l;
}
}p[maxn]; int mark[maxn]; int main()
{
int t,n;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=;i<n;i++)
{
scanf("%d%d",&p[i].l,&p[i].w);
}
sort(p,p+n);
//for(int i=0;i<n;i++) printf("%d %d\n",p[i].l,p[i].w);
int s=;
memset(mark,,sizeof(mark));
for(int i=;i<n;i++)
{
int temp=p[i].w;
if(!mark[i])
{
for(int j=i+;j<n;j++)
{
if(p[j].w>=temp&&!mark[j])
{
temp=p[j].w;
mark[j]=;
}
}
s++;
}
}
printf("%d\n",s);
}
return ;
}

dp:排序跟上面一样,然后就是找 w 的最长下降子序列。

 #include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn = ; struct point
{
int l,w;
bool operator < (const point &a) const
{
return l==a.l ? w<a.w : l<a.l;
}
}p[maxn]; int dp[maxn]; int main()
{
int t,n;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=;i<n;i++)
{
scanf("%d%d",&p[i].l,&p[i].w);
}
sort(p,p+n);
//for(int i=0;i<n;i++) printf("%d %d\n",p[i].l,p[i].w);
int ans=;
for(int i=;i<n;i++) dp[i]=;
for(int i=;i<n;i++)
{
for(int j=;j<i;j++)
if(p[j].w>p[i].w) dp[i]=max(dp[i],dp[j]+);
ans=max(ans,dp[i]);
}
printf("%d\n",ans);
}
return ;
}

最新文章

  1. SMA、SMB、SMC封装的二极管
  2. 我心目中的Asp.net核心对象
  3. CSS3-基于浮动的布局,响应式WEB设计,定位网页上的元素,设计打印页面的css技术
  4. 最简单的一个Oracle定时任务
  5. iOS开发ARC内存管理
  6. c++ 模板元编程的一点体会
  7. 转:ASP.NET MVC利用TryUpdateModel来做资料更新 (二)
  8. SVN与TortoiseSVN实战:属性的奇技淫巧(一)
  9. XSS的原理分析与解剖[转http://www.freebuf.com/articles/web/40520.html]
  10. InfluxDB安装
  11. android webview网页控件
  12. linux设备驱动----利用mdev(udev)自动创建设备文件节点
  13. VMware WorkStation安装时提示The MSI failed
  14. js 正则学习小记之匹配字符串
  15. jsp之用户自定义标签
  16. 【斐波那契数列】java探究
  17. 五、compose 部署 GitLab 应用
  18. Kibana中的Coordinate Map地图报索引错误的问题
  19. 去掉ambiguous expansion of macro警告
  20. load data妙用

热门文章

  1. EditPlus配置[C++] [Python] [Java] 编译运行环境
  2. 【BZOJ】【3238】【AHOI2013】diff(差异)
  3. thinkPHP生成静态分页列表
  4. Selenium获取input输入框中值的三种方法
  5. (转)Eclipse平台技术概述
  6. HDU 4027 Can you answer these queries?(线段树,区间更新,区间查询)
  7. js-jQuery对象与dom对象相互转换
  8. Java中常用的加密方法(JDK)
  9. Windows服务创建及安装
  10. ExtJs布局之BOX