求教昨晚网易游戏笔试第一题思路是不是这样的呢
请问一下昨晚的做了网易笔试的,第一题是不是这样做,没样例没法测,应该是背包问题,只是人气减2那里要从后往前推
int solve(int A, int B, int C, int start, int end)
{
vector<int> dp(2*end+1 , 0);
for (int i = start; i <= 2*end ; i++)
if (i >= start + 2)
dp[i] = dp[i - 2] + A;
for (int i = start; i <= 2*end; i++)
if (i >= 2 * start && i % 2 == 0)
dp[i] = min(dp[i], dp[i / 2] + B);
for (int i = 2*end-2; i >= start; i--)
dp[i] = min(dp[i], dp[i + 2] + C);
return dp[end];
}
#笔试题目#{
vector<int> dp(2*end+1 , 0);
for (int i = start; i <= 2*end ; i++)
if (i >= start + 2)
dp[i] = dp[i - 2] + A;
for (int i = start; i <= 2*end; i++)
if (i >= 2 * start && i % 2 == 0)
dp[i] = min(dp[i], dp[i / 2] + B);
for (int i = 2*end-2; i >= start; i--)
dp[i] = min(dp[i], dp[i + 2] + C);
return dp[end];
}