您的位置:首页 > 其它

UVa 357 - Let Me Count The Ways

2013-06-27 20:24 465 查看
/*UVa 357 - Let Me Count The Ways*/
import java.util.Scanner;

class Main {
public static void main(String[] args) throws Exception {
int arr[] = { 1, 5, 10, 25, 50 };
long dp[] = new long[30001];
dp[0] = 1;
for (int j = 0; j < 5; j++) {
for (int i = 1; i < 30001; i++) {
if (i >= arr[j])
dp[i] += dp[i - arr[j]];
}
}
Scanner scanner = new Scanner(System.in);
while (scanner.hasNextInt()) {
int n = scanner.nextInt();
if (dp
== 1) {
System.out.println("There is only 1 way to produce " + n
+ " cents change.");
} else {
System.out.println("There are " + dp
+ " ways to produce "
+ n + " cents change.");
}
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: