商品捆绑销售题目
来源:互联网 发布:天猫数据分析软件 编辑:程序博客网 时间:2024/04/29 00:46
同学发来的题目,让帮忙解决。
题目如下:
源程序:
代码有可以优化的地方,也没有添加输入数据异常的判断,只是一个思路的实现(大神勿喷)。
#define _CRT_SECURE_NO_WARNINGS#include <iostream>using namespace std;#define N 10//最大利润int main(){ int num; int comb_num;//组合 int cnt; int i,j; int max; int temp_i; int temp_j; int total_profit = 0; int profit_list[N][N]; //测试1 /*int profit_list[N][N]= { {0, 6, 62, 13}, {6, 0, 35, 94}, {62, 35, 0, 5}, {13, 94, 5, 0} };*/ //测试2 /*int profit_list[N][N]= { {0, 6, 62, 13, 1}, {6, 0, 35, 94, 2}, {62, 35, 0, 5, 3}, {13, 94, 5, 0, 4}, {1, 2, 3, 4, 0} };*/ cout<<"输入商品个数:"; cin>>num; cout<<"输入利润列表:"<<endl; for ( i = 0; i < num; i++) { for ( j = 0; j < num; j++) { cin>>profit_list[i][j]; } } comb_num = num/2; cnt = 0; max = profit_list[0][0]; while (cnt < comb_num) { for ( i = 0; i < num; i++) { for ( j = i; j < num; j++) { if (profit_list[i][j] > max) { temp_i = i; temp_j = j; max = profit_list[i][j];//找到最大值 } } } total_profit = total_profit + max;//记录最大利润 for ( i = 0; i < num; i++) { for ( j = 0; j < num; j++) { if ((i == temp_i) || (j == temp_j) || (i == temp_j) || (j == temp_i)) { profit_list[i][j] = 0;//清零 } } } cnt ++; max = 0; } cout<<"total_profit:"<<total_profit<<endl; cout<<endl; system("pause"); return 0;}
0 0
- 商品捆绑销售题目
- 商品销售
- 销售商品
- 商品销售
- C++习题 商品销售
- ACM--商品销售
- 简易商品销售
- 商品销售系统
- OJ商品销售
- YTU-OJ- 商品销售
- OJ商品销售
- OJ积累--商品销售
- 商品销售政策
- 某超市商品销售情况
- △【OJ】---N---商品销售
- 商品销售打折自定义的数据建模
- 商品销售打折自定义的数据建模
- 商品销售管理系统设计论文--毕业设计
- HDU1102&&POJ2421 Constructing Roads
- Java接口
- 使用Eclipse打开已有的工程
- 关于jsp中,调用根路径时发生的问题
- C++第三方常用库
- 商品捆绑销售题目
- 多维数组
- 我的博客
- 字符串反转方法1(main函数中直接反转)
- Caffe中学习率策略应如何选择
- Sass从安装到常用技巧
- 重构了一下简书。angular
- 九度OJ题目1172:哈夫曼树
- C++实现24点游戏