Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1320730
  • 博文数量: 179
  • 博客积分: 4141
  • 博客等级: 中将
  • 技术积分: 2083
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-21 20:04
文章存档

2024年(1)

2019年(13)

2016年(1)

2014年(16)

2011年(8)

2010年(25)

2009年(115)

分类:

2009-06-14 20:50:35

Number Partition

Time Limit:1sMemory limit:32M
Accepted Submit:38Total Submit:175

A partition of a positive integer m into n parts is defined to construct a sequence a1,..,an such that a1+...+an=m, and a1<=a2<=...<=an.

It is apparent that such partition is not unique. We arrange them in lexicographic order. Your task is to find the k-th sequence.

Input

There are multiple test cases. Each case has only 1 line with 3 integers: m,n,k (1<=n<=10, 1<=m<=220). Please note that k can be very large but are always within the range.
Process to the end of file.

Output

For each case, output a line containing the k-th sequence.

Sample Input

9 4 3

Sample Output

1 1 3 4

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>

using namespace std;

long long seq[12][222][222];

int main()
{
    long long i, j, l, u, e;
    long long n, m, k;
    long long fix;

    for (i = 1; i <= 10; ++i)
    {
        for (j = i; j <= 220; ++j)
        {
            if (i == 1)
                seq[i][j][j] = 1;
            else
            {
                for (l = 1; l <= j / i; ++l)
                {
                    seq[i][j][l] = 0;
                    e = (j - l) / (i - 1);
                    for (u = l; u <= e; ++u)
                        seq[i][j][l] += seq[i - 1][j - l][u];
                }
            }
        }
    }

    while (cin >> n >> m >> k)
    {
        fix = 1;
        while (m >= 1)
        {
            if (m == 1)
                cout << n << endl;
            else
            {
                while (seq[m][n][fix] < k)
                {
                    k -= seq[m][n][fix];
                    ++fix;
                }
                n -= fix;
                cout << fix << ' ';
            }
            --m;
        }
    }

    return 0;
}

阅读(1417) | 评论(0) | 转发(0) |
0

上一篇:三色二叉树

下一篇:Fire Net(二分图)

给主人留下些什么吧!~~