【十二题解】 | #放苹果#
放苹果
http://www.nowcoder.com/practice/bfd8234bb5e84be0b493656e390bdebf
#include<stdio.h>
int main(){
int apple, number;
while(scanf("%d", &apple) != EOF){
scanf("%d", &number);
int **dp = (int**)malloc(sizeof(int*)*(number+1));
for(int i=0; i<=number; i++){
dp[i]=(int*)malloc(sizeof(int)*apple+1);
dp[i][0]=1;
dp[i][1]=1;
}
for(int i=0; i<apple+1; i++){
dp[0][i]=1;
dp[1][i]=1;
}
int aa = dp[1][4];
for(int i=2; i<number+1; i++){
for(int j=2; j<apple+1; j++){
if(i > j){
dp[i][j]=dp[i-1][j];
}
else{
dp[i][j]=dp[i-1][j]+dp[i][j-i];
}
}
}
printf("%d\n", dp[number][apple]);
}
}