Nộp bài | Các bài nộp | Làm tốt nhất | Về danh sách bài |
HOUSES - Những ngôi nhà |
English | Vietnamese |
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: | C CPP PAS-FPC |
Nguồn bài: | VNOI Online Informatics Olympiad '09 Day 1 |