工作分配问题
2015-11-28 21:29
344 查看
#include<iostream> #include<fstream> using namespace std; const int MAX = 50; int n, m, k; int p[MAX][MAX]; int min = 1000000; //最小总费用 int cur = 0; //目前费用 int r[MAX]; void compute() { for(int i=1; i<=n; i++) cur += p[i][r[i]]; if(cur < min) min = cur; } void backtrack(int dep) { if(dep >= n) compute(); for(int i=dep+1; i<=n; i++) { swap(r[dep], r[i]); backtrack(dep+1); swap(r[dep], r[i]); } } int main() { ifstream fin("工作分配.txt"); cout << "\n输入工作数:"; fin >> n; cout << n; int i, j; cout << "\n输入工作费用矩阵:\n"; for(i=1; i<=n; i++) { for(j=1; j<=n; j++) { fin >> p[i][j]; cout << p[i][j] << "\t"; } cout << endl; } for(i=1; i<=n; i++) r[i] = i; backtrack(1); cout << "\n最小总费用为:" << min; cout << endl << endl; return 0; }
相关文章推荐
- Contest1040 - 第三届“图灵杯”NEUQ-ACM程序设计大赛(个人赛) A: 编程世界的大门
- win8/win10操作系统如何通过Legacy BIOS与UEFI两种模式安装
- 宏定义-C语言基础学习笔记
- Tips
- redis.conf 配置档详解
- androidStudio 自定义代码模板
- HDU 5587 Array
- 关于工作
- [Z] Closed-Form Solution与Numerical Solution
- UEFI装系统不能从U盘启动的解决办法
- linux mount/umount挂载命令解析。
- Fedora23安装有道词典
- 570B. Simple Game
- Ubuntu真机调试
- 第二个sprint第六天
- 定时器造成的内存泄露
- 2015.11.28----FaceAlignment by Explicit Shape Regression论文笔记
- logback logback.xml常用配置详解(二)<appender>
- CSS3总结
- passwd讲解