编程之美 买书问题java


import java.util.Comparator;

public class MaiBook {
	public static  float minCost(Integer[]num){
		float c5=Float.MAX_VALUE,c4=Float.MAX_VALUE,c3=Float.MAX_VALUE,c2=Float.MAX_VALUE,c1=Float.MAX_VALUE;//剩余找最小花费。
		/**
		 * 状态转移方程
		 */
		if(num[0]==0&&num[4]==0)return 0;
		if(num[4]>=1) {
			Integer[]tem=newNum(num,4);
			c5=(float) (40*0.75+minCost(tem));
		}
		if(num[3]>=1) {
			Integer[]tem=newNum(num,3);
			c4=(float) (32*0.8+minCost(tem));
		}
		if(num[2]>=1) {
			Integer[]tem=newNum(num,2);
			c3=(float) (24*0.9+minCost(tem));
		}
		if(num[1]>=1) {
			Integer[]tem=newNum(num,1);
			c2=(float) (16*0.95+minCost(tem));
		}
			Integer[]tem=newNum(num,0);
			c1=(float) (8+minCost(tem));
			return findMin(c1,c2,c3,c4,c5);
	}
	public static Integer[] newNum(Integer[]num,int n){
		Integer[] temp=new Integer[num.length];//深复制
		for(int i=0;i(){//重写排序
			@Override
			public int compare(Integer o1, Integer o2) {
				// TODO Auto-generated method stub
				return o2-o1;
			}
			
		});
		return temp;
	}
	public static float findMin(float c1,float c2,float c3,float c4,float c5){
		float min=c1;
		if(c2

 


你可能感兴趣的:(编程之美 买书问题java)