1689 建造高塔時間限制: 1 s空間限制: 128000 KB題目等級 : **鉆石 Diamond**
題目描述 Description
n有n種石塊,石塊能無限供應。每種石塊都是長方體,其中第i種石塊的長、寬、高分別為li、wi、hi。石塊可以旋轉,使得其中兩維成為長度和寬度,第三維成為高度。如果要把一個石塊放在另一個石塊上面,必須保證上面石塊的長和寬都分別嚴格小于下面石塊的長和寬。這意味著,即使兩塊長寬相同的石塊也不能堆砌起來。
現在神犇想知道,最多能用上多少塊石頭呢?
輸入描述 Input Description
第一行,N;
以下N行,每行三個數,表示第i種石頭的長寬高。
輸出描述 Output Description
一個整數,表示最多能用上多少塊石頭。
樣例輸入 Sample Input
3
1 1 1
2 2 2
3 3 4
樣例輸出 Sample Output
3
數據范圍及提示 Data Size & Hint
N≤50000,其余數字≤maxlongint。
分類標簽 Tags
**動態規劃**
#include<iostream>
#include<cstdio>
#include<algorithm>
#define MAXN 50001
using namespace std;
int n,tot,ans;
struct data{int x,y,tot;
}s[MAXN*6];
int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9') x=x*10+ch-48,ch=getchar();return x*f;
}
bool cmp(const data & x,const data & y)
{if(x.x!=y.x) return x.x<y.x;return x.y<y.y;
}
int main()
{int x,y,z;n=read();for(int i=1;i<=n;i++){x=read();y=read();z=read();s[++tot].x=x;s[tot].y=y;s[++tot].x=y;s[tot].y=x;s[++tot].x=y;s[tot].y=z;s[++tot].x=x;s[tot].y=z;s[++tot].x=z;s[tot].y=x;s[++tot].x=z;s[tot].y=y;}sort(s+1,s+tot+1,cmp);for(int i=1;i<=tot;i++){s[i].tot=1;for(int j=i-1;j>=1;j--){if(s[i].y>s[j].y&&s[i].x>s[j].x)s[i].tot=max(s[i].tot,s[j].tot+1);}}for(int i=1;i<=tot;i++)ans=max(ans,s[i].tot);printf("%d",ans);return 0;
}
#include<iostream>
#include<cstdio>
#include<algorithm>
#define MAXN 50001
using namespace std;
int n,tot,ans,l=1,c[MAXN*6];
struct data{int x,y,tot;
}s[MAXN*6];
int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9') x=x*10+ch-48,ch=getchar();return x*f;
}
int erfen(int x){int ll=0,r=l,mid;while(ll<r){mid=(r+ll)>>1;if(x>c[mid]) ll=mid+1;else r=mid;}return ll;
}
bool cmp(const data & x,const data & y)
{if(x.x!=y.x) return x.x<y.x;return x.y>y.y;
}
int main()
{int x,y,z;n=read();for(int i=1;i<=n;i++){x=read();y=read();z=read();s[++tot].x=x;s[tot].y=y;s[++tot].x=y;s[tot].y=x;s[++tot].x=y;s[tot].y=z;s[++tot].x=x;s[tot].y=z;s[++tot].x=z;s[tot].y=x;s[++tot].x=z;s[tot].y=y;}sort(s+1,s+tot+1,cmp);c[1]=s[1].y;for(int i=2;i<=tot;i++){s[i].tot=1;if(s[i].y>c[l]) c[++l]=s[i].y;else {int p=erfen(s[i].y);c[p]=s[i].y;}}printf("%d",l);return 0;
}