Give you a bag in a room with different sizes of golds. Pick up max amount into the bag. int PickUpGold(int[] golds, int capacity);
N*p
2 楼
好NP的问题。。。
【在 b*********y 的大作中提到】 : Give you a bag in a room with different sizes of golds. Pick up max amount : into the bag. : int PickUpGold(int[] golds, int capacity);
【在 b*********y 的大作中提到】 : Give you a bag in a room with different sizes of golds. Pick up max amount : into the bag. : int PickUpGold(int[] golds, int capacity);
p*2
6 楼
int PickUpGold(int[] golds, int capacity) { int[] dp=new int[capacity+1]; dp[0]=0;
【在 b*********y 的大作中提到】 : Give you a bag in a room with different sizes of golds. Pick up max amount : into the bag. : int PickUpGold(int[] golds, int capacity);
public static int PickUpGold(List golds, int capacity) { int max = 0; if (golds.Count == 1) { if (golds[0] <= capacity) { max = golds[0]; } } else if (golds.Count > 1 ) { for (int i=0; i< golds.Count; i++ ) { List gs = golds.ToList();
int total = golds[i]; if (capacity - golds[i] > 0) { gs.RemoveAt(i); total += PickUpGold(gs, capacity - golds[i]); } if (total > max && total <= capacity ) { max = total; if (max == capacity) { break; } } } } return max; }