http://oj.tsinsen.com/A1123
#include
#include
#include
using namespace std;
const int Inf = 1 << 20;
int n, k, Max, dp[500];
int TRes[500], Res[500];
void Dfs(int d) {
int sup;
for (int i = 1; i < 500; ++i)
dp[i] = Inf;
dp[0] = 0;
for (sup = 1; sup <= 500; ++sup) {
for (int i = 1; i <= d && TRes[i] <= sup; ++i)
dp[sup] = min(dp[sup], dp[sup - TRes[i]] + 1);
if (dp[sup] > n) {
if (--sup > Max) {
Max = sup;
copy(TRes + 1, TRes + d + 1, Res + 1);
}
break;
}
}
if (d >= k) return;
for (int i = sup + 1; i > TRes[d]; --i) {
TRes[d + 1] = i;
Dfs(d + 1);
}
}
int main() {
scanf("%d%d", &n, &k);
TRes[1] = 1; Dfs(1);
for (int i = 1; i <= k; ++i)
printf("%d ", Res[i]);
printf("\nMAX=%d\n", Max);
return 0;
}