POJ 1609

開始使用DAG的DP思路解決,然而忽略一個特殊情況,兩個box倘若相同尺寸,此時就不滿足DAG的限制了

這道題取了一個非常巧妙的思路,因爲box的l, m是固定的(也就是說不存在可以旋轉的問題),這道題巧妙的利用LIS的思路解決,在學習LIS的過程中,還順道瞭解了一個O(nlogn)的算法

#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <map>
#include <set>
#include <deque>
using namespace std;

const int maxn= 10005;
const int INF= 0x3f3f3f3f;

int n;
int dp[maxn];
pair<int, int> a[maxn];

int main(int argc, char const *argv[])
{
	while (~scanf("%d", &n) && n){
		for (int i= 0; i< n; ++i){
			scanf("%d %d", &a[i].first, &a[i].second);
		}
		sort(a, a+n);
		memset(dp, 0x3f, sizeof(dp));
		for (int i= 0; i< n; ++i){
			*upper_bound(dp, dp+n, a[i].second)= a[i].second;
		}
		printf("%d\n", (int)(lower_bound(dp, dp+n, INF)-dp));
	}
	putchar('*');
	return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章