zoukankan      html  css  js  c++  java
  • hdu 1069

    动态规划的题我弱爆了哎。。。。。

    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    struct node {
     int x,y,z;
    }a[3003];
    int cmp(const void *b,const void *c) {
     if((*(struct node *)b).x!=(*(struct node *)c).x)
      return (*(struct node *)b).x<(*(struct node *)c).x?1:-1;
     return (*(struct node *)b).y<(*(struct node *)c).y?1:-1;
    }
    int main() {
     int i,j,k=0,n,m,f[3001],b,c,d,max;
     while(scanf("%d",&n),n) {
      m=0;
      for(i=0;i<n;i++) {
       scanf("%d%d%d",&b,&c,&d);
       a[m].x=b;
       a[m].y=c;a[m++].z=d;
       a[m].x=b;a[m].y=d;a[m++].z=c;
       a[m].x=c;a[m].y=d;a[m++].z=b;
      }
      for(i=0;i<m;i++)
       if(a[i].x<a[i].y) {
        d=a[i].x;
        a[i].x=a[i].y;
        a[i].y=d;
       }
       qsort(a,m,sizeof(a[0]),cmp);
       memset(f,0,sizeof(f));
       f[0]=a[0].z;
       for(i=1;i<m;i++) {//每次以当前位置为终止位置来求从0开始的最优解
        max=0;
        for(j=i-1;j>=0;j--) {
         if(a[j].x>a[i].x&&a[j].y>a[i].y||a[j].x>a[i].y&&a[j].y>a[i].x) {
          if(f[j]>max)
          max=f[j];
         }
        }
        f[i]=max+a[i].z;
       }
       max=0;
       for(i=0;i<m;i++)
        if(max<f[i])
         max=f[i];
        printf("Case %d: maximum height = %d ",++k,max);
      }
      return 0;
     }
      

  • 相关阅读:
    Shell变量
    Shell执行脚本
    C++类的默认成员函数
    C# CAD 二次开发(二) -集成开发环境VS2012+CAD2016
    C# CAD 二次开发(一) -前期搜集资料篇
    WPF 学习笔记(十二)
    WPF 学习笔记(十一)
    WPF 学习笔记(十)
    WPF 学习笔记(九)
    WPF 学习笔记(八)
  • 原文地址:https://www.cnblogs.com/thefirstfeeling/p/4410968.html
Copyright © 2011-2022 走看看