POJ 1065 & ZOJ 1025
I'm so stupid...I have Waed so many times on this problem...
这是神奇的Dilworth定理的一个应用,可以自行google一下,非常amazing的一个theory
以木头的一个性质(例如长度升序排列),之后将思路转化为了最长下降子序列(这里的下降是针对另一个性质),DP求解。
实际上相当于把题目中,不需要setup time时的条件看作是一个偏序,然后这就是一个显然对Dilworth定理。
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int maxn= 5e3+5;
const int INF= 0x7f7f7f7f;
struct Wod{
int l, w;
Wod()= default;
Wod(int ll, int ww) : l(ll), w(ww) {}
bool operator < (const Wod& a) const{
return l< a.l || (l== a.l && w< a.w);
}
}wds[maxn];
int lds[maxn], flg[maxn];
int ans= -INF;
void Init()
{
memset(flg, 0, sizeof(flg));
memset(lds, 0, sizeof(lds));
memset(wds, 0, sizeof(wds));
}
int main()
{
int T, n;
scanf("%d", &T);
while (T--){
Init();
scanf("%d", &n);
int l, w;
for (int i= 1; i<= n; ++i){
scanf("%d %d", &l, &w);
wds[i]= Wod(l, w);
}
sort(wds+1, wds+n+1);
for (int i= 1; i<= n; ++i){
for (int j= 1; j< i; ++j){
if (wds[j].w > wds[i].w && lds[j] > lds[i]){
lds[i]= lds[j];
}
}
++lds[i];
ans= max(ans, lds[i]);
}
printf("%d\n", ans);
}
return 0;
}
POJ 1065 & ZOJ 1025的更多相关文章
- POJ 1065 Wooden Sticks(zoj 1025) 最长单调子序列
POJ :http://poj.org/problem?id=1065 ZOJ: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId= ...
- POJ 1562 && ZOJ 1709 Oil Deposits(简单DFS)
题目链接 题意 : 问一个m×n的矩形中,有多少个pocket,如果两块油田相连(上下左右或者对角连着也算),就算一个pocket . 思路 : 写好8个方向搜就可以了,每次找的时候可以先把那个点直接 ...
- POJ 1065 Wooden Sticks / hdu 1257 最少拦截系统 DP 贪心
参考链接:http://blog.csdn.net/xiaohuan1991/article/details/6956629 (HDU 1257 解题思路一样就不继续讲解) POJ 1065题意:给你 ...
- POJ 3076 / ZOJ 3122 Sudoku(DLX)
Description A Sudoku grid is a 16x16 grid of cells grouped in sixteen 4x4 squares, where some cells ...
- poj 3100 (zoj 2818)||ZOJ 2829 ||ZOJ 1938 (poj 2249)
水题三题: 1.给你B和N,求个整数A使得A^n最接近B 2. 输出第N个能被3或者5整除的数 3.给你整数n和k,让你求组合数c(n,k) 1.poj 3100 (zoj 2818) Root of ...
- POJ 1065
http://poj.org/problem?id=1065 题目的大体意思就是给一些木头长l,重w,有一个机器,如果切割这些木头的话,在i后面切割的i+1根木头满足长度和重量都要大于等于前一根则不需 ...
- poj -1065 Wooden Sticks (贪心or dp)
http://poj.org/problem?id=1065 题意比较简单,有n跟木棍,事先知道每根木棍的长度和宽度,这些木棍需要送去加工,第一根木棍需要一分钟的生产时间,如果当前木棍的长度跟宽度 都 ...
- poj 1080 zoj 1027(最长公共子序列变种)
http://poj.org/problem?id=1080 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=27 /* zoj ...
- [poj] 2396 [zoj] 1994 budget || 有源汇的上下界可行流
poj原题 zoj原题 //注意zoj最后一行不要多输出空行 现在要针对多赛区竞赛制定一个预算,该预算是一个行代表不同种类支出.列代表不同赛区支出的矩阵.组委会曾经开会讨论过各类支出的总和,以及各赛区 ...
随机推荐
- 3亿(int)数据-2亿(int)数据 求差集
两个大文本,每行一条int数据 3亿(int)数据-2亿(int)数据 求差集 原始(粗暴)办法 1redis set 或类似方案 本地内存 cpu都撑不住 2持久化两张表 sql join mysq ...
- Django ORM单表查询必会13条
必知必会13条 操作下面的操作之前,我们实现创建好了数据表,这里主要演示下面的操作,不再细讲创建准备过程 <1> all(): 查询所有结果 <2> filter(**kwar ...
- Klotski's Blog
教材: 唐朔飞 编著 "计算机组成原理(第2版)"高等教育出版社 2008年1月 习题指导教材: 唐朔飞 编著 "计算机组成原理–学习指导与习题解答(第2版)" ...
- elasticsearch用法
基本原理 搜索引擎的索引 倒排序 由value查找key 数据库的索引 由key查找value 用于解决分库分表后的排序分页 like查找 性能问题 日志库的全文搜索 spring集成时使用的不是re ...
- [LC] 64. Minimum Path Sum
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which ...
- list split批量处理
<dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-colle ...
- 手机安装fiddler证书
如果电脑浏览器和手机抓包有证书问题,那就把电脑的证书都删除,然后在fiddler里重置,手机上删除不了单个证书,可以重新下载一个证书安装 如果电脑抓包正常,手机抓包不正常,那就手机重新下载证书安装 手 ...
- [LC] 100. Same Tree
Given two binary trees, write a function to check if they are the same or not. Two binary trees are ...
- Ionic3学习笔记(六)存储之使用 SQLite
本文为原创文章,转载请标明出处 目录 安装 CURD操作 1. 安装 命令行输入 ionic cordova plugin add cordova-sqlite-storage npm install ...
- The Process class relies on proc_open, which is not available on your PHP installation报错解决
同事laravel框架开发的代码有如下错误日志 production.ERROR: The Process class relies on proc_open, which is not availa ...