题解 | #放苹果#
放苹果
https://www.nowcoder.com/practice/bfd8234bb5e84be0b493656e390bdebf
import java.util.*; public class Main { public static void main(String[] args) { Scanner fzhinput = new Scanner(System.in); int pgnum = fzhinput.nextInt(); int pznum = fzhinput.nextInt(); System.out.println(fppg(pgnum,pznum)); } private static int fppg(int pg, int pz){ int sz[][] = new int[pg+1][pz+1]; for(int i=0;i<=pz;i++){ sz[0][i]=1; } for(int i=0;i<=pg;i++){ sz[i][1]=1; } for(int i=1;i<=pg;i++){ for(int j=2;j<=pz;j++){ if(i<j){ sz[i][j]=sz[i][i]; } else{ sz[i][j]=sz[i-j][j]+sz[i][j-1]; } } } return sz[pg][pz]; } }