Problem hidden
|This problem was hidden by Editorial Board member probably because it has incorrect language|version or invalid test data, or description of the problem is not clear.|

HOUSES - Những ngôi nhà

Houses

A construction company invested in building a row of L houses in a street. There are N people who want to buy these houses. The ith buyer will buy ai houses and each one will only buy consecutive houses. Because the number of houses to be sold may be smaller than the total number of houses (L), there are some houses not to be sold. To ensure the beauty of the area, the company will always sell the first house (in left to right order).

Given the requirements of each buyer, a way for the company to sell houses can be represented by a sequence of L numbers, in which the ith number is 0 if the ith house will not be sold and is k if the ith house will be sold to the kth buyer.

For example, if L=4, N=2, a1 = 2, a2=1, the sequence "2 0 1 1" represents a way to sell houses for the company: the first house will be sold to the second buyer, the 3rd and 4th houses will be sold to the first buyer and the second house will not be sold.

Help the company to enumerate the ways to sell houses. The ways to sell houses should be enumerated by the lexicographical order of the corresponding sequences. If there are more than 1000 ways to sell houses, only enumerate the first 1000 ways (sequence a preceeds sequence b in lexicographical order iff there exists j so that ai=bi for all i < j and aj < bj).

Input

  • First line: two integers L, N.
  • Second line: N integers a1, a2, ..., an.

Constraints

  • 1 ≤ L ≤ 100.
  • 1 ≤ N ≤ 20.
  • a1 + a2 + ... + aN ≤ L.

Output

Each line of the output corresponds to a sequence representing a way for the company to sell houses. Two consecutive numbers are separated by a space. The sequences are enumerated by lexicographical order.

Example

Input
4 2
2 1

Output
1 1 0 2
1 1 2 0
2 0 1 1
2 1 1 0

Được gửi lên bởi:Jimmy
Ngày:2008-07-29
Thời gian chạy:0.200s
Giới hạn mã nguồn:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Ngôn ngữ cho phép:Tất cả ngoại trừ: ERL GOSU JS-RHINO NODEJS PERL6 PYPY RUST SED VB.NET
Nguồn bài:VNOI Online Informatics Olympiad '09
Day 1

hide comments
2022-07-26 21:42:48
1 hit ac
2021-05-27 18:01:16
Tham khảo: https://vnspoj.github.io/problems/HOUSES
2017-11-17 04:49:24
ai = 0 duoc ko a
2017-07-27 12:06:07
Code AC: http://ideone.com/eQ3Nte
2017-02-06 14:15:00
sai lỗi easy
2016-11-03 15:44:29
Backtrack với chú ý là mỗi ngôi nhà sẽ có 2 khả năng là bán hoặc không bán. Nếu bán thì sẽ bán các nhà liên tiếp. Nếu không bán thì phải thỏa mãn bán đủ cho N người.
http://thuattoan.phamvanlam.com/spoj-com-thuat-toan-bai-houses-nhung-ngoi-nha/
2016-09-30 10:29:05
Trâu cũng AC =)))
2016-09-30 10:24:36
Please be careful, leave short comments only. Don't spam here.
2016-09-30 10:24:14
Don't post any source code here.
2016-09-05 09:06:38
Mình quay lui bình thường vẫn AC đây đâu cần đặt cận đâu
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.