当前位置: 代码迷 >> 综合 >> HDOJ 1028 Ignatius and the Princess III
  详细解决方案

HDOJ 1028 Ignatius and the Princess III

热度:116   发布时间:2023-10-21 20:07:31.0

HDACM1028
母函数
母函数原理

import java.util.Scanner;public class Main{public static void main(String[] args) {int[] f = new int [121];int[] temp = new int[121];for (int i = 0; i < f.length; i++) {f[i]=1;  // 1~120 全部由1相加}for (int i = 2; i <= 120; i++) {for (int j = 0; j <= 120; j++) {for (int k = 0; i*k+j<=120;k++) {
   //1~120由1~i组成的所有可能temp[i*k+j] += f[j];}}for (int j = 0; j <= 120; j++) {f[j] = temp[j];temp[j] = 0;}}Scanner sc = new Scanner(System.in);while (sc.hasNext()) {int n = sc.nextInt();System.out.println(f[n]);}}
}