博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
1.4买书问题C#源码
阅读量:6258 次
发布时间:2019-06-22

本文共 3184 字,大约阅读时间需要 10 分钟。

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Maishuwenti {
class Program {
public const int larg = 100000; static void Main(string[] args) {
int[] n1 = new int[] {
3,4,2,1,0}; double solution = find_BestSol(n1[0],n1[1],n1[2],n1[3],n1[4]); Console.WriteLine("最好的解决方案{0}", solution); Console.ReadLine(); } public static double find_BestSol(int x1, int x2, int x3, int x4, int x5) {
int[] n = new int[5] { x1, x2, x3, x4, x5 }; rerank(ref n); x1 = n[0]; x2 = n[1]; x3 = n[2]; x4 = n[3]; x5 = n[4]; if (n[0] > 0) {
Console.WriteLine("n[0]>0"); return Min(8.0 + find_BestSol(x1, x2, x3, x4, x5 - 1), 2 * 8 * 0.95 + find_BestSol(x1, x2, x3, x4 - 1, x5 - 1), 3 * 8 * 0.9 + find_BestSol(x1, x2, x3 - 1, x4 - 1, x5 - 1), 4 * 8 * 0.8 + find_BestSol(x1, x2 - 1, x3 - 1, x4 - 1, x5 - 1), 5 * 8 * 0.75 + find_BestSol(x1 - 1, x2 - 1, x3 - 1, x4 - 1, x5 - 1)); } else if ((n[0] == 0) && (n[1] > 0)) {
Console.WriteLine("n[1]>0"); return Min(8.0 + find_BestSol(x1, x2, x3, x4, x5 - 1), 2 * 8 * 0.95 + find_BestSol(x1, x2, x3, x4 - 1, x5 - 1), 3 * 8 * 0.9 + find_BestSol(x1, x2, x3 - 1, x4 - 1, x5 - 1), 4 * 8 * 0.8 + find_BestSol(x1, x2 - 1, x3 - 1, x4 - 1, x5 - 1), larg); } else if ((n[0] == 0) && (n[1] == 0) && (n[2] > 0)) {
Console.WriteLine("n[2]>0"); return Min(8.0 + find_BestSol(x1, x2, x3, x4, x5 - 1), 2 * 8 * 0.95 + find_BestSol(x1, x2, x3, x4 - 1, x5 - 1), 3 * 8 * 0.9 + find_BestSol(x1, x2, x3 - 1, x4 - 1, x5 - 1), larg, larg); } else if ((n[0] == 0) && (n[1] == 0) && (n[2] == 0) && (n[3] > 0)) {
Console.WriteLine("n[3]>0"); return Min(8.0 + find_BestSol(x1, x2, x3, x4, x5 - 1), 2 * 8 * 0.95 + find_BestSol(x1, x2, x3, x4 - 1, x5 - 1), larg, larg, larg); } else if ((n[0] == 0) && (n[1] == 0) && (n[2] == 0) && (n[3] == 0) && (n[4] > 0)) {
Console.WriteLine("n[4]>0"); return 8.0 + find_BestSol(x1, x2, x3, x4, x5 - 1); } else {
Console.WriteLine("都为0"); return 0; } } public static void rerank(ref int [] m) {
//冒泡排序 for (int i = m.Length-1; i >0; i--) {
for (int j = 0; j < i; j++) {
if (m[j]>m[j +1]) {
int temp; temp = m[j + 1]; m[j + 1] = m[j]; m[j] = temp; } } } } public static double Min(double a, double b, double c, double d, double e) {
double[] n = new double[5]; n[0] = a; n[1] = b; n[2] = c; n[3] = d; n[4] = e; Console.WriteLine("最小值为{0}", n.Min()); return n.Min(); } } }

转载于:https://www.cnblogs.com/hold/archive/2012/01/02/2310005.html

你可能感兴趣的文章
Android开发之ListView-SimpleAdapter的使用
查看>>
App.config提示错误“配置系统未能初始化”
查看>>
Angular - - ngChange、ngChecked、ngClick、ngDblclick
查看>>
JAVA学习第五十九课 — 网络编程概述
查看>>
远程共享文件夹
查看>>
convert2utf8withbom
查看>>
Codeforces Round #336 (Div. 2)A. Saitama Destroys Hotel 水题
查看>>
poj2752 Seek the Name, Seek the Fame(next数组的运用)
查看>>
pgpgin|pgpgout|pswpin|pswpout意义与差异
查看>>
全排列(递归与非递归实现)
查看>>
[转] C/C++中printf和C++中cout的输出格式
查看>>
swift 如何实现点击view后显示灰色背景
查看>>
【Android】3.9 覆盖物功能
查看>>
Plus One
查看>>
Git -- 创建版本库
查看>>
myeclipse 怎么安装与激活
查看>>
Atitit.异步编程的发展历史 1.1. TAP & async/await
查看>>
RTP timestamp与帧率及时钟频率的关系
查看>>
企业门户平台解决方案
查看>>
过滤器入门
查看>>