Codeforces 459C Pashmak and Buses(构造)
来源:互联网 发布:大数据知识结构 编辑:程序博客网 时间:2024/05/05 20:57
题目链接: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;}
0 0
- Codeforces 459C Pashmak and Buses(构造)
- codeforces 459C - Pashmak and Buses 【构造题】
- CodeForces 459C-G - Pashmak and Buses-构造-K进制
- Codeforces problem 459C Pashmak and Buses
- codeforces C. Pashmak and Buses
- 【CODEFORCES】 C. Pashmak and Buses
- Codeforces 459C Pashmak and Buses 可重集排列
- C - Pashmak and Buses
- CF 459C(Pashmak and Buses-分治)
- codeforces #261 C题 Pashmak and Buses(瞎搞)
- Codeforces #261 (Div. 2) C. Pashmak and Buses(数学)
- Codeforces Round #261 (Div. 2) C. Pashmak and Buses
- Codeforces Round #261 (Div. 2) C. Pashmak and Buses
- Codeforces Round #261 (Div. 2) C. Pashmak and Buses
- cf459C Pashmak and Buses
- Codeforces Round #261 (Div. 2)——Pashmak and Buses
- CF. Pashmak and Buses(分析)
- CF459C Pashmak and Buses 打印全排列
- 黑马程序员--安卓22期毕业19天就业50人平均薪资8261
- objective-c 复制对象
- POJ训练计划3020_Antenna Placement(二分图/最大匹配)
- 最小生成树prime算法模板
- 关于在Java使用反射对属性取值和赋值的性能问题。
- Codeforces 459C Pashmak and Buses(构造)
- 上传内容和http keep alive
- plsql登录数据库出错,ora-01034:oracle not available ora-27101: shared memory realm does not exis
- JVM
- 打造最佳开发团队的几点建议
- sql trim()函数去掉两头空格,编程要注意空格的地方
- 异步下载sendAsynchronousRequest:...方法
- socket编程指南
- mfc appxxx