#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int N = 1010;
typedef long long LL;
int n;
int a[N];
LL f[N];
int main(){
while (scanf("%d", &n) && n){
memset(a, 0, sizeof a);
memset(f, 0, sizeof f);
for (int i = 1; i <= n; i ++ ) cin >> a[i];
for (int i = 1; i <= n; i ++ ){
f[i] = a[i];
for (int j = 1; j < i; j ++ )
if (a[j] < a[i])
f[i] = max(f[i], f[j] + a[i]);
}
LL res = 0;
for (int i = 1; i <= n; i ++ ) res = max(res, f[i]);
printf("%lld\n", res);
}
return 0;
}
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int N = 2010;
int n;
int a[N];
int f[N];
int main(){
while (~scanf("%d", &n)){
memset(a, 0, sizeof a);
memset(f, 0, sizeof f);
for (int i = 1; i <= n; i ++ ) cin >> a[i];
for (int i = 1; i <= n; i ++ ){
f[i] = 1;
for (int j = 1; j < i; j ++ )
if (a[j] < a[i])
f[i] = max(f[i], f[j] + 1);
}
int res = 0;
for (int i = 1; i <= n; i ++ ) res = max(res, f[i]);
printf("%d\n", res);
}
return 0;
}
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int N = 110;
int n, casei;
int f[N];
struct node{
int l,w,h;
}p[N];
bool cmp(node A, node B){
if (A.l != B.l) return A.l > B.l;
else{
if (A.w != B.w) return A.w > B.w;
else return A.h > B.h;
}
}
int main(){
while (scanf("%d", &n) && n){
memset(p, 0, sizeof p);
memset(f, 0, sizeof f);
int m = 0;
for (int i = 1; i <= n; i ++ ){
int a[3];
scanf("%d%d%d", &a[0], &a[1], &a[2]);
sort(a, a + 3);
p[++ m] = {a[2],a[1],a[0]};
p[++ m] = {a[2],a[0],a[1]};
p[++ m] = {a[1],a[0],a[2]};
}
sort(p + 1, p + 1 + m, cmp);
for (int i = 1; i <= m; i ++ ){
f[i] = p[i].h;
for (int j = 1; j < i; j ++ )
if (p[j].l > p[i].l && p[j].w > p[i].w)
f[i] = max(f[i], f[j] + p[i].h);
}
int res = 0;
for (int i = 1; i <= m; i ++ )
res = max(res, f[i]);
printf("Case %d: maximum height = %d\n", ++ casei, res);
}
return 0;
}
快一点,我到第三题了,在线等,挺急的。
啊这,不得自己琢磨琢磨0.0
hh