算法实现:时间复杂度(n^2)
int Lc(int num[], int n)
{
int i,j, max = 0;
int list[n];
for(i = 0; i < n; i++)
{
list[i] = 1;
for(j = 0; j < i; j++)
{
if(num[i] > num[j] && list[j] >= list[i])
{
list[i] = list[j] + 1;
}
}
}
return max;
}
hdu 1069:这题可以通过数据的预处理,把它转化为最长不下降子序列问题。
code:
#include<stdio.h>
#include<stdlib.h>
#define N 35
struct Node
{
int x, y, z;
int max;
}node[N*6];
int cmp(const void* a, const void* b)
{
struct Node *c = (Node*)a;
struct Node *d = (Node*)b;
if(c->x != d->x)return c->x - d->x;
else if(c->y != d->y)return c->y - d->y;
else return c->z - d->z;
}
int main()
{
int xi[N], yi[N], zi[N];
int n;
int i, j, k;
int max = 0;
int cas = 1;
while(scanf("%d", &n ) && n)
{
k = 0;
for(i = 0; i < n; i++)
{
scanf("%d %d %d", &xi[i], &yi[i], &zi[i]);
node[k].x = xi[i];
node[k].y = yi[i];
node[k++].z = zi[i];
node[k].x = xi[i];
node[k].y = zi[i];
node[k++].z = yi[i];