[英]Structures in C++, initializations
class box{
int l,w,h;
box(int a,int b,int c){
l = a;w = b;h = c;
};
};
bool cmp(box a,box b){
return a.l*a.w<b.l*b.w;
}
class Solution{
public:
/*The function takes an array of heights, width and
length as its 3 arguments where each index i value
determines the height, width, length of the ith box.
Here n is the total no of boxes.*/
int maxHeight(int h[],int w[],int l[],int n)
{
//Your code here
struct box b[(3*n)]={};
int j = 0;
for(int i = 0 ; i< n; ++ i){
b[j++] = box(min(l[i],w[i]),max(l[i],w[i]),h[i]);
b[j++] = box(min(l[i],h[i]),max(l[i],h[i]),w[i]);
b[j++] = box(min(w[i],h[i]),max(w[i],h[i]),l[i]);
}
n*=3;
sort(b,b+n,cmp);
int dp[n];
for(int i = 0 ; i< n; ++ i){
dp[i] = b[i].h;
}
int ans = INT_MIN;
for(int i = 1; i< n; ++ i){
for(int j = 0; j< i; ++ j){
if(b[i].l>b[j].l and b[i].w>b[j].w and dp[i]<dp[j]+b[i].h)
dp[i] = b[i].h+dp[j];
}
ans = max(ans,dp[i]);
}
return ans;
}
};
上面的代码显示了一个错误,即结构变量采用 3 arguments 并且仅给出 1,如图所示。 请帮我解决这个问题。 谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.