https://codeforces.com/problemset/problem/459/C
思路:
这题愣是看错题意搞了1小时不对。题意就是两个人不要在同一辆车上就好了,虽然可以还是一辆车,但是不是同一辆车就好。
列出二维数组可以发现,其就是一个从下到上(上面高位)的k进制数,每次枚举进位模拟就好了。
#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e3+100;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar(); while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL a[maxn][maxn];
int main(void){
cin.tie(0);std::ios::sync_with_stdio(false);
LL n,k,d;cin>>n>>k>>d;
double temp=1;
for(LL i=1;i<=d;i++) temp*=k;
if((double)n>temp){ cout<<"-1"<<"\n";return 0;}
///最后输出+1
for(LL j=2;j<=n;j++){
for(LL i=d;i>=1;i--) a[i][j]=a[i][j-1];
a[d][j]++;
LL roundup=0;
if(a[d][j]>=k){
a[d][j]=0;
roundup=1;
}
if(roundup){
for(LL i=d-1;i>=1;i--){
a[i][j]++;
if(a[i][j]<k){
roundup=0;
break;
}
else{
a[i][j]=0;
}
}
}
}
for(LL i=1;i<=d;i++){
for(LL j=1;j<=n;j++){
a[i][j]++;
cout<<a[i][j]<<" ";
}
cout<<"\n";
}
return 0;
}