MOOC清华《程序设计基础》第6章:橱窗插花问题(递推法)
最新推荐文章于 2020-03-06 21:23:53 发布

sunshineman1986 于 2017-07-20 14:12:33 发布
#include <iostream>
using namespace std;
int V = 5;
int F = 3;
int main()
{
void ToBinary(int num, int binary[]);
int Count1(int binary[], int &high);
int beauty[V][F] = {{7,5,-21},
{23,21,5},
{-5,-4,-4},
{-24,10,-20},
{16,23,20}};
int best_beauty = 0, best_put = 0;
int partial_sum[1 << V] = {0};
for(int i = 1; i < (1 << V); i++)
{
int binary[V] = {0};
ToBinary(i, binary);
int high;
int flowers = Count1(binary, high);
if(flowers > F)
continue;
partial_sum[i] = partial_sum[i - (1 << high)] + beauty[high][flowers - 1];
if(flowers == F && partial_sum[i] > best_beauty)
{
best_beauty = partial_sum[i];
best_put = i;
}
}
cout << "最大美感得分和:" << best_beauty << endl;
cout << "插花方法:";
int best_binary[V] = {0};
ToBinary(best_put, best_binary);
for(int vase = 0, flower = 1; vase < V; vase++)
if(best_binary[vase] == 1)
{
cout << flower;
flower++;
}
else
cout << 0;
return 0;
}
void ToBinary(int num, int binary[])
{
for(int i = 0; i < V; i++)
{
binary[i] = num & 1;
num = num >> 1;
}
}
int Count1(int binary[], int &high)
{
int count = 0;
high = -1;
for(int i = 0; i < V; i++)
if(binary[i] == 1)
{
high = i;
count++;
}
return count;
}

测试代码附带运行时的结果:


相关知识
第6章花卉的花期调控.ppt
第6章花卉的花期调控
园艺植物栽培学第6章
2023年汉江师范学院普通专升本《C语言程序设计》考试大纲
插花艺术(第3版)
森林有害生物控制(北京林业大学) 中国大学MOOC答案2024版100分完整版 – 中国大学MOOC答案
new第6章1景观生态学
第49届ICPC国际大学生程序设计竞赛亚洲区域赛(南京)在我校举行
第6章
第49届ICPC国际大学生程序设计竞赛亚洲区域赛(南京)在我校成功举行
原文链接: MOOC清华《程序设计基础》第6章:橱窗插花问题(递推法) https://m.huajiangbk.com/newsview708887.html
| 上一篇: 花仕插花花艺培训新课程,【插花与... | 下一篇: 潮汕宴会插花课程设计.docx |


