ACM学习-动态规划-巡回演出问题
来源:互联网 发布:指纹考勤机数据修改 编辑:程序博客网 时间:2024/05/16 11:35
// ACM学习-动态规划-巡回演出问题.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<iostream>
using namespace std;
int n=3;
int data[100][100] = {
{130,150},
{75,0,80},
{120,110,0,100,110,120,0},
{60,70,60,50},
{0,135,140},
{70,80},
};
int circle[100] = {
2,3,7,4,3,2
};
int mincost[100][100][50] = { -1 };
int k=6;//要飞的航班数
int muti;
int sum;
int first=0;
int last=2;
//返回start---end 走steps步需要的最少花费
int get(int start,int end,int steps){
if (mincost[start][end][steps] > -1)return mincost[start][end][steps];
int result=10000;
//int count = 0;
if (steps == 1){
int temp;
if (end>start)
temp = data[start*muti + end - 1][steps-1];
else
temp = data[start*muti + end][steps - 1];
if (temp != 0){
//cout << " temp=" << temp << endl;
return temp;
}
else{
return 10000;
}
}
for (int i = 0; i < n; i++){
if (i != end){
int temp;
if (end>i)
temp = data[i*muti + end - 1][steps-1];
else
temp = data[i*muti + end][steps - 1];
if (temp != 0){
if (steps == 2 && end != start&&i==first){
continue;
}
//count++;
int cost = get(start, i,steps-1) + temp;
if (cost < result&&cost<10000)
result = cost;
//cout << "cost=" << cost << endl;
}
}
}
if (result < 10000)mincost[start][end][steps] = result;
return result;
}
int _tmain(int argc, _TCHAR* argv[])
{
memset(mincost, 0xff, sizeof(mincost));
muti = n - 1;
sum = n*(n - 1);
for (int i = 0; i < sum; i++){
for (int j = circle[i]; j < k; j++){
data[i][j] = data[i][j%circle[i]];
}
}
for (int i = 0; i < sum; i++){
for (int j = 0; j < k; j++){
cout << data[i][j] << ends;
}
cout << endl;
}
cout << get(0, 2, 6) << endl;
return 0;
}
//
#include "stdafx.h"
#include<iostream>
using namespace std;
int n=3;
int data[100][100] = {
{130,150},
{75,0,80},
{120,110,0,100,110,120,0},
{60,70,60,50},
{0,135,140},
{70,80},
};
int circle[100] = {
2,3,7,4,3,2
};
int mincost[100][100][50] = { -1 };
int k=6;//要飞的航班数
int muti;
int sum;
int first=0;
int last=2;
//返回start---end 走steps步需要的最少花费
int get(int start,int end,int steps){
if (mincost[start][end][steps] > -1)return mincost[start][end][steps];
int result=10000;
//int count = 0;
if (steps == 1){
int temp;
if (end>start)
temp = data[start*muti + end - 1][steps-1];
else
temp = data[start*muti + end][steps - 1];
if (temp != 0){
//cout << " temp=" << temp << endl;
return temp;
}
else{
return 10000;
}
}
for (int i = 0; i < n; i++){
if (i != end){
int temp;
if (end>i)
temp = data[i*muti + end - 1][steps-1];
else
temp = data[i*muti + end][steps - 1];
if (temp != 0){
if (steps == 2 && end != start&&i==first){
continue;
}
//count++;
int cost = get(start, i,steps-1) + temp;
if (cost < result&&cost<10000)
result = cost;
//cout << "cost=" << cost << endl;
}
}
}
if (result < 10000)mincost[start][end][steps] = result;
return result;
}
int _tmain(int argc, _TCHAR* argv[])
{
memset(mincost, 0xff, sizeof(mincost));
muti = n - 1;
sum = n*(n - 1);
for (int i = 0; i < sum; i++){
for (int j = circle[i]; j < k; j++){
data[i][j] = data[i][j%circle[i]];
}
}
for (int i = 0; i < sum; i++){
for (int j = 0; j < k; j++){
cout << data[i][j] << ends;
}
cout << endl;
}
cout << get(0, 2, 6) << endl;
return 0;
}
0 0
- ACM学习-动态规划-巡回演出问题
- ACM学习-动态规划-背包问题
- ACM学习-动态规划-子问题编码
- ACM学习-动态规划-取数字问题
- ACM学习-动态规划-购物问题
- ACM学习-动态规划-物品供应问题
- ACM学习-动态规划-电子眼问题
- ACM学习-动态规划-复制书稿问题
- ACM学习-动态规划-采购计划问题
- ACM学习-动态规划-文本压缩问题
- ACM学习-动态规划-子问题编码-散列表
- ACM学习-动态规划-基因查找序列问题
- ACM学习-动态规划-不老的传说问题
- ACM学习-动态规划-三角形最大面积问题
- 学习ACM之动态规划
- 学习ACM之动态规划
- 学习ACM之动态规划
- ACM:动态规划,01背包问题
- hdu 5481 Desiderium(高效)
- JS中给函数参数添加默认值
- animation的step-start
- 关于java的点点滴滴(2) final关键字
- iOS开发- UICollectionView详解+实例
- ACM学习-动态规划-巡回演出问题
- POJ - 1321 棋盘问题(15.10.10 搜索专题)dfs
- 判断字符串是否是回文的代码实现
- SVN命令使用详解
- CANCEL
- UITableView添加UIRefreshControl,实现简单刷新
- hdu 5482 Numquam vincar(暴力)
- 拓扑数据分析与机器学习的相互促进
- jQuery中 $.ajax()方法详解