problem 1093
来源:互联网 发布:网页优化方案 编辑:程序博客网 时间:2024/06/07 07:16
经典题 最长上升子序列
先把每一个箱子都拆成六个(全排列),然后对其中的 X 坐标排序,再然后以 Z 为权值(即高度),Y 上升为条件DP。做法几乎和最长上升子序列一模一样。
Accepted 1093 C 00:00.02 404K
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int cmp(const void* a,const void* b)
{
return *((int*)b) - *((int*)a);
}
void solve(int n)
{
int size[180][3] = {0};
int i,j;
int m[180];
for (i = 0; i < 6 * n; i += 6)
{
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
size[i][0] = x;size[i][1] = y;size[i][2] = z;
size[i + 1][0] = x;size[i + 1][1] = z;size[i + 1][2] = y;
size[i + 2][0] = y;size[i + 2][1] = x;size[i + 2][2] = z;
size[i + 3][0] = y;size[i + 3][1] = z;size[i + 3][2] = x;
size[i + 4][0] = z;size[i + 4][1] = x;size[i + 4][2] = y;
size[i + 5][0] = z;size[i + 5][1] = y;size[i + 5][2] = x;
}
qsort(size,6 * n,sizeof(size[0]),cmp);
for (i = 0; i < 6 * n; i++)
{
int max = 0;
for (j = 0; j < i; j++)
{
if (size[j][1] > size[i][1] && size[j][0] > size[i][0])
max = max > m[j] ? max : m[j];
}
m[i] = max + size[i][2];
}
int ans = 0;
for (i = 0; i < 6 * n; i++)
ans = ans > m[i] ? ans : m[i];
printf("maximum height = %d/n",ans);
}
void main()
{
#ifndef ONLINE_JUDGE
freopen("1093.txt","r",stdin);
#endif
int n,t = 0;
while (scanf("%d",&n) != EOF && n != 0)
{
printf("Case %d: ",++t);
solve(n);
}
#ifndef ONLINE_JUDGE
fclose(stdin);
#endif
}
#include<stdlib.h>
#include<string.h>
int cmp(const void* a,const void* b)
{
return *((int*)b) - *((int*)a);
}
void solve(int n)
{
int size[180][3] = {0};
int i,j;
int m[180];
for (i = 0; i < 6 * n; i += 6)
{
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
size[i][0] = x;size[i][1] = y;size[i][2] = z;
size[i + 1][0] = x;size[i + 1][1] = z;size[i + 1][2] = y;
size[i + 2][0] = y;size[i + 2][1] = x;size[i + 2][2] = z;
size[i + 3][0] = y;size[i + 3][1] = z;size[i + 3][2] = x;
size[i + 4][0] = z;size[i + 4][1] = x;size[i + 4][2] = y;
size[i + 5][0] = z;size[i + 5][1] = y;size[i + 5][2] = x;
}
qsort(size,6 * n,sizeof(size[0]),cmp);
for (i = 0; i < 6 * n; i++)
{
int max = 0;
for (j = 0; j < i; j++)
{
if (size[j][1] > size[i][1] && size[j][0] > size[i][0])
max = max > m[j] ? max : m[j];
}
m[i] = max + size[i][2];
}
int ans = 0;
for (i = 0; i < 6 * n; i++)
ans = ans > m[i] ? ans : m[i];
printf("maximum height = %d/n",ans);
}
void main()
{
#ifndef ONLINE_JUDGE
freopen("1093.txt","r",stdin);
#endif
int n,t = 0;
while (scanf("%d",&n) != EOF && n != 0)
{
printf("Case %d: ",++t);
solve(n);
}
#ifndef ONLINE_JUDGE
fclose(stdin);
#endif
}
- problem 1093
- problem
- Problem
- problem
- Problem
- Problem
- Problem
- Problem
- Problem
- Problem
- problem
- Problem
- Problem
- Problem
- Problem
- Problem
- Problem
- Problem
- 基于栈指纹检测缓冲区溢出的一点思路
- Spring让Hibernate使用者受益良多
- 双表法调用样式表
- 在Ring3上实现文件碎甲(解锁)功能
- 结构型设计模式总结(上)
- problem 1093
- 用myeclipse生成hibernate映射文件
- 缓存使用错误及解决
- Edit控件密码窗口的秘密--一种全新的通用密码记录技术
- XHTML代码规范
- 结构型设计模式总结(下)
- ASP.NET无限级分类的非递归实现(存储过程版)
- 结合存储过程开发数据库应用程
- Js小技巧合集