#include #include #define INF 999999 int dp[100][100]; int min(int a, int b); int main(){ int N; int S[11]; int i, j, k; scanf("%d",&N); for (i = 0; i <= N; i++){ scanf(" %d",&S[i]); } memset(dp,INF,sizeof(dp)); dp[0][0] = 1; for (i = 0; i <= N; i++){ for (j = 0; j <= S[N]; j++){ for (k = 0; k <= S[N]; k++){ dp[i + 1][j] = min(dp[i][j] + dp[0][k], dp[i + 1][j]); if (j + k + 1 > S[i]){ continue; } dp[i][j + k + 1] = min(dp[i][j]+dp[i][k],dp[i][j+k+1]); } } } for (i = 0; i < S[N]; i++){ printf("%d ",dp[N][i]); } printf("%d\n",dp[N][S[N]]); return 0; } int min(int a, int b){ if (a >= b){ return b; } else{ return a; } }