题目链接:Codeforces 459C Pashmak and Buses
题目大意:有n个学生,d天,k辆车,每天会到一个不同的地方,即要乘坐一次车,要求每人两个学生在每一天共同乘坐一辆车。个数安排方案。
解题思路:每个学生的乘坐方案即使一个长度为d,元素范围1~k的序列,不出现重复即可。dfs处理出方案,方案数足够后跳出递归。
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn = 1005;
ll d, k;
int n, c, v[maxn][maxn], arr[maxn];
bool judge () {
ll ret = 1;
for (int i = 1; i <= d; i++) {
ret *= k;
if (ret >= n)
return true;
}
return false;
}
void solve (int u) {
if (d == u) {
memcpy(v[c++], arr, sizeof(arr));
return;
}
int& i = arr[u];
for (i = 1; i <= k; i++) {
solve(u+1);
if (c == n)
return;
}
}
int main () {
scanf("%d%lld%lld", &n, &k, &d);
if (judge ()) {
c = 0;
solve(0);
for (int i = 0; i < d; i++) {
printf("%d", v[0][i]);
for (int j = 1; j < n; j++)
printf(" %d", v[j][i]);
printf("\n");
}
} else
printf("-1\n");
return 0;
}
分享到:
相关推荐
暴枚最长桌脚的长度$l$,然后长度比$l$长的桌脚全部都要砍掉长度比$l$短的桌脚选择代价前$k$小的砍掉用线段树维护;示例程序 :typedef long l
Codeforces 题库 101-200 共~500题 codeforces.com版权所有。 程序可提交至该网站评测。
Codeforces 题库 001-100 共~500题 codeforces.com版权所有。 程序可提交至该网站评测。
codeforces编程网站预测分数插件
Codeforces 1105B - Zuhair and Strings 测试点37个(全)
使用于Google Chrome的Codeforces Enhancer 1.1.2插件安装包。 版本:codeforces enhancer 1.1.2 使用浏览器:Google Chrome
Codeforces 185A - Plant 全测试点49个
codeforces 19 E Fairy 一道比较难的题目的解题报告 推荐阅读
Codeforces global round 10 codes
Codeforces round 678 division 2 codes
Codeforces Round #632 (Div. 2) C. Eugene and an array 题意: 求出一个数列中子区间满足 此区间的任意子区间之和 不为0的区间个数。 思路: 考虑用dp[x]dp[x]dp[x]记录前缀和为xxx的区间右端点。 那么这道题其实...
Some of the Codeforces problems codes
Codeforces - 1107B. Digital root & 1107C. Brutality(规律 & 贪心)Codeforces - 1107B.
使用 C# + WPF 开发 ...你只需要提前构造好某些题的叉点数据,填入它,OK!一切就是这么的方便! 注:仅适用于 Edu 以及 Div.3 轮比赛赛后 hack,不支持 Div.1/2 赛时 hack。 适用人群:想进入首页 Hack 榜的选手
codeforces每日一题。 题意: 给出一个数组,让你挑选出能组成任意pair差值为2的幂的序列,并且使这个序列长度尽可能大。 思路: 针对于挑选出来的序列,任意pair对的差值为2的幂数。 假设有多个pair对,设dis(a,b)=2...
Codeforces round 678 D2_Codeforces_源码
打codeforces的神器
lucifer1004大佬的博客cf上分攻略故里大佬的githubcf思维题刷题数:44- (1421)codeforces 676 div2 A,B done
codeforces-js Codeforces JS
一个Codeforces、牛客竞赛、AtCoder平台的编程竞赛查询插件,ACMer必备.zip