The rapid growth of Internet of Things (IoT) devices and the increasing need for low-latency and high-throughput applications have led to the introduction of distributed edge computing. Flying fog computing is a promising solution that can be used to assist IoT networks. It leverages drones with computing capabilities (e.g., fog nodes), enabling data processing and storage closer to the network edge. This introduces various benefits to IoT networks compared to deploying traditional static edge computing paradigms, including coverage improvement, enabling dense deployment, and increasing availability and reliability. However, drones’ dynamic and mobile nature poses significant challenges in task offloading decisions to optimize resource utilization and overall network performance. This work presents a novel offloading model based on dynamic programming explicitly tailored for flying fog-based IoT networks. The proposed algorithm aims to intelligently determine the optimal task assignment strategy by considering the mobility patterns of drones, the computational capacity of fog nodes, the communication constraints of the IoT devices, and the latency requirements. Extensive simulations and experiments were conducted to test the proposed approach. Our results revealed significant improvements in latency, availability, and the cost of resources.