Description

Recently Pashmak has been employed in a transportation company. The company has kbuses and has a contract with a school which has n students. The school planned to take the students to d different places for d days (each day in one place). Each day the company provides all the buses for the trip. Pashmak has to arrange the students in the buses. He wants to arrange the students in a way that no two students become close friends. In his ridiculous idea, two students will become close friends if and only if they are in the same buses for all d days.

Please help Pashmak with his weird idea. Assume that each bus has an unlimited capacity.

Input

The first line of input contains three space-separated integers n, k, d (1 ≤ n, d ≤ 1000; 1 ≤ k ≤ 109).

Output

If there is no valid arrangement just print -1. Otherwise print d lines, in each of them print nintegers. The j-th integer of the i-th line shows which bus the j-th student has to take on thei-th day. You can assume that the buses are numbered from 1 to k.

Examples
input
3 2 2
output
1 1 2 
1 2 1
input
3 2 1
output
-1
Note

Note that two students become close friends only if they share a bus each day. But the bus they share can differ from day to day.

题意:有K台公交,n个人,d天,任意两个人全部d天都不能做同一辆公交,输出这种安排

解法:K台公交安排d天,自然是Kd种方法,Ki大于等于n说明符合要求,再将1~n变成k进制保证题目要求,然后按照题目要求输出

 #include<bits/stdc++.h>
using namespace std;
#define ll long long
ll Pow(ll a,ll b)
{
ll ans=;
ll base=a;
while(b)
{
if(b&)
{
ans*=base;
}
base*=base;
b>>=;
}
return ans;
}
ll n,k,d;
ll solve[][];
int main()
{
int flag=;
cin>>n>>k>>d;
for(int i=;i<=d;i++)
{
if(Pow(k,i)>=n)
{
flag=;
break;
}
}
if(flag)
{
for(int i=;i<=n;i++)
{
ll num=i;
for(int j=;j<=d;j++)
{
solve[i][j]=num%k+;
num/=k;
}
}
for(int i=;i<=d;i++)
{
for(int j=;j<=n;j++)
{
cout<<solve[j][i]<<" ";
}
cout<<endl;
}
}
else
{
cout<<"-1"<<endl;
}
return ;
}

最新文章

  1. js和jquery如何获取图片真实的宽度和高度
  2. 【Solr】新建core后,启动服务访问web报错 HTTP Status 503
  3. 数据结构代码整理(线性表,栈,队列,串,二叉树,图的建立和遍历stl,最小生成树prim算法)。。持续更新中。。。
  4. JQuery阻止冒泡事件on绑定中异常情况分析
  5. MySQL Innodb的两种表空间方式
  6. docker-hub 账户
  7. [Java] Serializable(序列化)的理解
  8. andorid 文字颜色selector的使用
  9. 第二百九十九天 how can I 坚持
  10. C#核心语法
  11. 【转】VC中对文件的读写
  12. html5 + css3 + zepto.js实现的微信广告宣传页
  13. JuliaSet&amp;MandelBulb @ Maya&amp;KK —— 4亿粒子的测试
  14. php mysql 实现消息队列
  15. HDU 2167 Pebbles(状压DP)
  16. Alpha冲刺(5/10)——2019.4.27
  17. Java 中关于基本数字类型的注意事项
  18. js动态改变setInterval的时间
  19. python 打开浏览器的方法 Python打开默认浏览器
  20. dep包安装与依赖库

热门文章

  1. openwrt procd 运行的一些log
  2. js replace()实现全部替换
  3. ros使用时的注意事项&amp;技巧2
  4. (C)strcpy ,strncpy与strlcpy
  5. 优秀Java程序员必须了解的GC工作原理
  6. POJ1651 Multiplication Puzzle —— DP 最优矩阵链乘 区间DP
  7. Vue实现仿淘宝商品详情属性选择的功能
  8. 正则表达式、Calendar类、SimpleDateFormat类、Date类、BigDecimal类、BigInteger类、System类、Random类、Math类(Java基础知识十四)
  9. ubuntu下tesseract 4.0安装及参数使用
  10. CodeForces-607B:Zuma (基础区间DP)