m0_55766293 2021-04-16 18:20 采纳率: 20%
浏览 57

Matlab如何解决这个问题

magine a shopping mall, where the stores try to help each other out. Purchasing any item from one store means that you can choose one, and only one, coupon to another store, good for that day only. Of course, if you buy something from that other store, you can get a coupon for a third store, and so forth. Each coupon is for a different amount, so store X might give you a $5 off coupon for store Y, but store Y might give you a $10 off coupon for store X. Fortunately, they publish a list in advance, so you can plan your trip. Or you can have your computer figure it out for you.

For this assignment, write a program to figure out how to get the maximum savings for a set number of items. To keep things simple, assume that you need one item from each store, and that the price of each item is more than the coupon. To get the coupon amounts, you can use random values like


    coupons = randi(100, N, N);

for N stores. Put zeros in the diagonals, or ignore them, since a store is not going to give a coupon for itself.

To make this clear, suppose that you have the following table. The left-most column is the "from" store, and the top-most row is the "to" store. For example, buying something at store w and means that you can collect a $5 coupon for store x.

One solution is to go from store w to z (+45), then from z to x (+51), then x to y (+10), for a total savings of $106.

Have your program count the number of comparisons that it does. You can simply increment a variable right before an "if" statement, though keep in mind that any functions that you call will also factor into this. For example, if you call a sort function, assume that it counts for N * log(N) comparisons every time it is called with N values. A min or max function requires N-1 comparisons.

Once you have this working, have it report the number of comparisons for 2 stores, 3 stores, 4 stores, and so forth, until you can establish the growth rate. When it goes from N to N+1 stores, how many more comparisons will it have to do?

  • 写回答

2条回答 默认 最新

  • CSDN专家-黄老师 2021-04-17 16:55
    关注

    你这个更多是数学计算方面的问题,建议先用数学逻辑计算出来再用代码实现

    评论

报告相同问题?

悬赏问题

  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像