Cf459c pashmak and buses print in full order

Source: Internet
Author: User

If we look at the final result vertically, the number of each column can be regarded as a K-hexadecimal number. There is a total of D columns, and any two columns are different, therefore, this is a problem of fully arranging D-bit K-in-number. K ^ d is arranged in total. If K ^ d <n,-1 is printed.

When the final result is printed, set the first column to 1 1 1... 1. Then, add 1 to each column in sequence (the bus number starts from 1, not from 0). Note that this is k-based.

# Include <stdlib. h> # include <stdio. h> # include <algorithm> # include <vector> # include <math. h> using namespace STD; int tmpvalue [1001] [1001]; int main () {# ifdef _ debugfreopen ("D: \ in.txt", "r", stdin ); # endifint N, K, D; scanf ("% d", & N, & K, & D); If (k <n) {int Total = 1; for (INT I = 1; I <= D; I ++) {total * = K; If (total> = N) {break ;}} if (total <n) {printf ("-1 \ n"); Return 0 ;}}for (INT I = 1; I <= D; I ++) {tmpvalue [I] [1] = 1 ;}for (INT I = 2; I <= N; I ++) {for (Int J = 1; j <= D; j ++) {tmpvalue [J] [I] = tmpvalue [J] [I-1];} tmpvalue [1] [I] + = 1; for (Int J = 1; j <= D; j ++) {If (tmpvalue [J] [I]> K) {tmpvalue [J] [I] = 1; tmpvalue [J + 1] [I] ++;} elsebreak ;}}for (INT I = 1; I <= D; I ++) {for (Int J = 1; j <= N; j ++) {printf ("% d", tmpvalue [I] [J]);} printf ("\ n");} return 0 ;}


cf459c pashmak and buses print in full order

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.