当前位置: 代码迷 >> 综合 >> HDOJ 2069 Coin Change--百钱买百鸡解法
  详细解决方案

HDOJ 2069 Coin Change--百钱买百鸡解法

热度:64   发布时间:2023-10-21 20:25:04.0

HDACM2069
题目类似于百钱买百鸡,博主有个限制没看到一直WA,就是 Your program should be able to handle up to 100 coins.意思是硬币的个数不能超过100个,我并没有注意到这个,英语差就很头疼/(ㄒoㄒ)/~~

import java.util.Scanner;public class Main{public static void main(String[] args) {Scanner sc = new Scanner(System.in);while (sc.hasNext()) {int n = sc.nextInt();long count = 0;for (int i = 0; i <= n; i++) {for (int j = 0; i+j*5 <= n; j++) {for (int j2 = 0; i+j*5+j2*10 <= n; j2++) {for (int k = 0; i+j*5+j2*10+k*25 <= n; k++) {for (int k2 = 0; i+j*5+j2*10+k*25+k2*50 <= n; k2++) {if (i+j*5+j2*10+k*25+k2*50==n&&i+j+j2+k+k2<=100) {count++;}}}}}}System.out.println(count);}}
}
  相关解决方案