https://www.acmicpc.net/problem/2655
2655번: 가장높은탑쌓기
첫째 줄에는 입력될 벽돌의 수가 주어진다. 입력으로 주어지는 벽돌의 수는 최대 100개이다. 둘째 줄부터는 각 줄에 한 개의 벽돌에 관한 정보인 벽돌 밑면의 넓이, 벽돌의 높이 그리고 무게가 차
www.acmicpc.net
[ 백준 2655번 가장높은탑쌓기 소스 코드 ]
#include <cstdio>
#include <algorithm>
using namespace std;
int z[110]={0,},p[110]={0,},max1=0,max2=0,b[110],o;
struct sung
{
int n; //번호
int s; //넓이
int h; //높이
int w; //무게
}da[110];
void go(int x)
{
if( x==0 ) return;
go(p[x]);
b[o] = da[x].n;
o++;
}
int cmp(sung x,sung y)
{
if( x.s<y.s ) return 1;
else return 0;
}
int main()
{
int i,j,m,t,x;
scanf("%d", &m);
for(i=1;i<=m;i++)
{
da[i].n = i;
scanf("%d %d %d", &da[i].s,&da[i].h,&da[i].w);
}
sort(da,da+m+1,cmp);
for(i=1;i<=m;i++)
{
t = 0;
x = 0;
for(j=1;j<i;j++)
{
if( da[i].w>da[j].w && t<z[j] )
{
t = z[j];
x = j;
}
}
z[i] = t + da[i].h;
p[i] = x;
if( max1<z[i] )
{
max1 = z[i];
max2 = i;
}
}
go(max2);
printf("%d\n", o);
for(i=0;i<o;i++) printf("%d\n", b[i]);
return 0;
}
'백준 문제풀이' 카테고리의 다른 글
백준 14002 - 가장 긴 증가하는 부분 수열4 (0) | 2021.11.15 |
---|---|
백준 2605번 줄세우기 (0) | 2021.10.20 |
백준 10989 수 정렬하기3 소스 코드 (0) | 2021.10.08 |
백준 10814 나이순 정렬 소스 코드 (0) | 2021.10.08 |
백준 2568번 전깃줄 소스코드 (0) | 2021.07.31 |