it is not possible to do it in this manner
you can take one simple example and dry run it you will realize that it will stuck in a cycle
correct way to do this is
recursive code look like:
// CellMitosis.cpp
#include<bits/stdc++.h>
using namespace std;
int CellMitosis(int n,int x,int y,int z) {
// base case:
if (n <= 1) return 0;
// recursion:
int mincost=INT_MAX;
if (n % 2 == 0) {
mincost = min(mincost, x + CellMitosis(n / 2, x, y, z));
mincost = min(mincost, y + CellMitosis(n - 1, x, y, z));
}
else {
mincost = min(mincost, x + z + CellMitosis((n + 1) / 2 , x, y, z));
mincost = min(mincost, y + CellMitosis(n - 1, x, y, z));
}
return mincost;
}
int main() {
int n,x,y,z;
cin >> n;
cin >> x >> y >> z;
cout << CellMitosis(n,x,y,z) << endl;
}
i hope this help
if you have more doubts regarding this feel free to ask
if your doubt is resolved mark it as resolved from your doubt section inside your course