/**
* Program Name: Stick.java
* Purpose: use dynamic programming to minimize the cost of cutting wood
* Author: Shiuh-Sheng Yu
* Department of Information Management
* National Chi Nan University
* Since: 2011/04/22
*/
import java.util.Scanner;
public class Stick {
public static int dynamic(int[] at) {
}
public static void main(String[] argv) {
Scanner input = new Scanner(System.in);
int len;
while (input.hasNextInt() && (len = input.nextInt()) != 0) {
int[] at = new int[input.nextInt()+2];
for (int i = 1; i < at.length-1; i++)
at[i] = input.nextInt();
at[at.length-1] = len;
long start = System.currentTimeMillis();
int optimal = dynamic(at);
long stop = System.currentTimeMillis();
System.out.println("The minimum cutting is "+optimal+". used "+(stop-start)+" ms.");
}
}
}
* Program Name: Stick.java
* Purpose: use dynamic programming to minimize the cost of cutting wood
* Author: Shiuh-Sheng Yu
* Department of Information Management
* National Chi Nan University
* Since: 2011/04/22
*/
import java.util.Scanner;
public class Stick {
public static int dynamic(int[] at) {
}
public static void main(String[] argv) {
Scanner input = new Scanner(System.in);
int len;
while (input.hasNextInt() && (len = input.nextInt()) != 0) {
int[] at = new int[input.nextInt()+2];
for (int i = 1; i < at.length-1; i++)
at[i] = input.nextInt();
at[at.length-1] = len;
long start = System.currentTimeMillis();
int optimal = dynamic(at);
long stop = System.currentTimeMillis();
System.out.println("The minimum cutting is "+optimal+". used "+(stop-start)+" ms.");
}
}
}
最後修改: 2012年 09月 3日(週一) 19:40