The Tower of Babylon UVA - 437(바빌론 타워, DP)
제목: 나무 덩어리를 쌓는 데 있어서 윗부분의 밑면의 길이는 반드시 다음 덩어리의 길이보다 작아야 하며, 최대 쌓는 높이가 얼마나 되는지 물어야 한다.사고방식: 고전적인 문제입니다. 지금 쓰세요.호남 여러 학교에서 비슷한 것을 만났지만 2차원 모델이다. 그 문제는 그림을 만드는 방법을 사용했고 H-Highest Tower CSU-2017도 dp의 방법으로 만들 수 있을 것이다. 다음에 다시 보충할 것이다.
#include
#include
#include
#include
#include
using namespace std;
const int maxn = 105;
int n;
int dp[maxn][3];// i j
int cube[maxn][3];
void trans(int *v,int a,int b)
{
int cnt = 0;
for(int i = 1;i <= 3;i++)
{
if(i == b)continue;
v[cnt++] = cube[a][i];
}
}
int solve(int a,int b)
{
int &ans = dp[a][b];// ans dp ,
if(ans > 0)
return ans;
ans = 0;
for(int i = 1;i <= n;i++)
{
for(int j = 1;j <= 3;j++)
{
int v1[2],v2[2];
trans(v1,i,j);
trans(v2,a,b);
if(v1[0] < v2[0] && v1[1] < v2[1])
ans = max(ans,solve(i,j));
}
}
ans += cube[a][b];
return ans;
}
int main()
{
int kase = 0;
while(~scanf("%d",&n) && n)
{
memset(dp,0,sizeof(dp));
for(int i = 1;i <= n;i++)
{
for(int j = 1;j <= 3;j ++)
{
scanf("%d",&cube[i][j]);
}
sort(cube[i] + 1,cube[i] + 1 + 3);
}
int ans = 0;
for(int i = 1;i <= n;i++)
{
for(int j = 1;j <= 3;j++)
{
ans = max(ans,solve(i,j));
}
}
printf("Case %d: maximum height = ",++kase);
printf("%d
",ans);
}
return 0;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Rails Turbolinks를 페이지 단위로 비활성화하는 방법원래 Turobolinks란? Turbolinks는 링크를 생성하는 요소인 a 요소의 클릭을 후크로 하고, 이동한 페이지를 Ajax에서 가져옵니다. 그 후, 취득 페이지의 데이터가 천이 전의 페이지와 동일한 것이 있...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.