zoukankan      html  css  js  c++  java
  • hdu 1069 Monkey and Banana

    郁闷呐,课件说是搜索题,结果搜了半天还是超时,看来剪枝的能力还是不行呀

    最后,悲剧的用简单的DP过的

    这题目用DP 的思想还是比较简单的

    #include<iostream>
    using namespace std;
    int n,height[100],max1;
    struct node
    {
    	int x,y,z,area;
    	node(int _x=0,int _y=0,int _z=0):x(_x),y(_y),z(_z)
    	{
    		area=x*y;
    	};
    }a[100];
    int cmp(const void* a1,const void *a2)
    {
    	return (*(node*)a2).area-(*(node*)a1).area;
    }
    bool fun(int a1,int b1,int a2,int b2)
    {
    	if((a1<a2&&b1<b2)||(a1<b2&&b1<a2))
    		return true;
    	return false;
    }
    int main()
    {
    	int x,y,z,cas=0;
    	while(cin>>n&&n)
    	{
    		int b=0;
    		for(int i=0;i<n;i++)
    		{
    			cin>>x>>y>>z;
    			a[b++]=node(x,y,z);
    			a[b++]=node(y,z,x);
    			a[b++]=node(z,x,y);
    		}
    		n=n*3;
    		qsort(a,n,sizeof(node),cmp);
    		max1=-1;
    		memset(height,0,sizeof(height));
    		height[0]=a[0].z;
    		for(int i=1;i<n;i++)
    		{
    			int temp=0;
    			for(int j=0;j<i;j++)
    			{
    				if(fun(a[i].x,a[i].y,a[j].x,a[j].y)&& temp<height[j])
    				{
    					temp=height[j];
    				}
    			}
    			height[i]=temp+a[i].z;
    			if(height[i]>max1)
    				max1=height[i];
    		}
    		cout<<"Case "<<++cas<<": maximum height = "<<max1<<endl;	
    	}
    	return 0;
    }
    				
    
  • 相关阅读:
    android个版本对应的SDK level,最新包括android10.0
    SQL语句 存在就更新不存在就插入
    forward和sendredirect
    JavaBean
    Cookie单点登录跨域问题
    JSP
    JSP内置对象
    Spring学习笔记
    事务
    AOP实现方式
  • 原文地址:https://www.cnblogs.com/nanke/p/2127343.html
Copyright © 2011-2022 走看看