二维数组中最大采集和的 c 阶运动

I've been having trouble with a problem, something like this:

I have a 2D array where each position is filled with a certain number samples (represented by ints). There are nanorobots, each going in a straight line through a part of a line of column (each with a pre-specified way), collecting all samples along the way. If a nanorobot collects samples on a position, the position becomes contaminated and if another robot comes there, it gets confused and stops. I can deploy the robots in any order, and each robot starts working only after the previous one has stopped.

With this information, I want to find the order in which the highest number of samples is collected.

Any help with the problem would be appreciated, as I am pretty stumped. I have a general idea of how it's done, but can't seem to move forward. One thing specifically is how do I mark which places a robot has been to so that i know where other robots should stop if they come there, every solution I've come up with seems really slow. Thanks.

转载于:https://stackoverflow.com/questions/53249237/c-order-of-movement-in-a-2d-array-for-maximum-sum-collected

csdnceshi78
程序go The number of samples on a position is represented by one int, sorry for not being clear.
11 个月之前 回复
csdnceshi78
程序go I honestly don't have much yet, however I was thinking to add visited positions to an array and then compare current element to those in the array, but that's slow. Second idea was to add bools to every position to signify if it was visited, but I'd have to change every bool to false after every iteration, which seems slow also.
11 个月之前 回复
csdnceshi73
喵-见缝插针 If all samples are positive ints, then you can use a negative value to indicate it was visited. You also say each position can have multiple samples (ints), so your array probably should have lists containing the [variable amount of] samples.
11 个月之前 回复
csdnceshi66
必承其重 | 欲带皇冠 Welcome to Stack Overflow. Please read the help pages, take the SO tour, read about how to ask good questions, as well as this question checklist. Lastly learn how to create a Minimal, Complete, and Verifiable Example.
11 个月之前 回复
csdnceshi69
YaoRaoLov Can you post your code?
11 个月之前 回复

1个回答

To help you developing your algorithms, I provide you with a possible data structure:

typedef struct LIST {
    int sample;
    struct LIST *next;
} t_list;

typedef struct ITEM {
    t_list *samples;
    int visited;
} t_item;

t_item items[10][10];

This defines an array of 10x10 items. Each item has a list of samples and an indicator that it has been visited ("contaminated"). A list element (a sample) has the sample value and a pointer to the next list element (the next sample). I hope this helps.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!