• hdu1069Monkey and Banana


    1[i][j]其中i表示由i个箱子堆起来,j表示这堆箱子最上面的一个是第j个,

    2突然被排列三个数卡主了,基础问题啊

    3一开始是想到排列高度,后来想到排列底,最后想到路径解决它

    #include "iostream"
    #include "string.h"
    using namespace std;
    struct student{
      int c,k,g;
    }num[100];
    int max(int a,int b){return a>b?a:b;}
    void maxb(int &a,int &b,int &c){
        int t;
        if(a<b){t=a;a=b;b=t;}
        if(b<c){t=b;b=c;c=t;}
        if(a<b){t=a;a=b;b=t;}
    }
    int main(){
      int n,pos,a,b,c,i,f[100][100],m,j,k,top=1;
      while(1){
        cin>>n;pos=1;
        if(!n)break;
        for(i=1;i<=n;i++){
          cin>>a>>b>>c;
          maxb(a,b,c);
          //cout<<a<<b<<c<<"****"<<endl;
          num[pos].c=a;num[pos].k=b;num[pos].g=c;pos++;
          num[pos].c=a;num[pos].k=c;num[pos].g=b;pos++;
          num[pos].c=b;num[pos].k=c;num[pos].g=a;pos++;
        }
        m=0;
        memset(f,0,sizeof(f));
        for(i=1;i<pos;i++){f[1][i]=num[i].g;m=max(m,num[i].g);}
        //cout<<1<<' ';for(i=1;i<pos;i++)cout<<f[1][i]<<' ';cout<<endl;
        for(i=2;i<pos;i++){
          for(j=1;j<pos;j++){
            for(k=1;k<pos;k++){
              if(num[k].c>num[j].c&&num[k].k>num[j].k){
                f[i][j]=max(f[i][j],f[i-1][k]+num[j].g);
                m=max(f[i][j],m);
              }
            }
          }
          //cout<<i<<' ';for(j=1;j<pos;j++)cout<<f[i][j]<<' ';cout<<endl;
        }
        cout<<"Case "<<top++<<": maximum height = "<<m<<endl;
      }
    }

    也粘贴上网上的代码给大家看看

    Input
    int cur = 0;
                for(i=0; i<n; ++i) {
                    scanf("%d %d %d",&a,&b,&c);
                    q[cur].x = a>b ? a: b;
                    q[cur].y = a>b ? b: a;
                    q[cur].h = c;
                    cur ++;
                    q[cur].x = c>b ? c: b;
                    q[cur].y = c>b ? b: c;
                    q[cur].h = a;
                    cur ++;
                    q[cur].x = a>c ? a: c;
                    q[cur].y = a>c ? c: a;
                    q[cur].h = b;
                    cur ++;
                }
     

    其中分别对长跟宽做排序,接着......

    qsort(q,cur,sizeof(q[0]),cmp);
    
                int max = 0;
                for(i=0; i<cur; ++i){
                    dp[i]=q[i].h;
                      for(j=0; j<i; ++j){
                            if(q[i].y<q[j].y && q[i].x<q[j].x) dp[i] = dp[i] > dp[j]+q[i].h ? dp[i] : dp[j]+q[i].h;
                      }
                      max = max > dp[i] ? max : dp[i];
                }
                printf("Case %d: maximum height = %d
    ",++k, max);
  • 相关阅读:
    [LeetCode] Permutations II
    [LeetCode] Remove Duplicates from Sorted Array II
    [LeetCode] Permutations
    [LeetCode] Path Sum II
    [LeetCode] Plus One
    [LeetCode] Path Sum
    [LeetCode] Permutation Sequence
    [LeetCode] Pow(x, n)
    [LeetCode] Remove Duplicates from Sorted Array
    [LeetCode] Remove Element
  • 原文地址:https://www.cnblogs.com/dowson/p/3270962.html
Copyright © 2020-2023  润新知