@
yuriko @
3pointer 写的很垃圾,求拍砖
public int solution(int[] selectiveDates)
{
int [] minCost = new int[31];
for (int date = 0; date < 31; date++)
{
int oneDayAgo = 0;
if (date - 1 > 0)
oneDayAgo = date - 1;
if (selectiveDates.Contains(date))
{
int sevenDaysAgo = 0;
if (date - 7 > 0)
sevenDaysAgo = date - 7;
int thirtyDaysAgo = 0;
if (date - 30 > 0)
thirtyDaysAgo = date - 30;
minCost[date] = Math.Min(minCost[sevenDaysAgo] + 7, minCost[thirtyDaysAgo] + 25);
minCost[date] = Math.Min(minCost[date], minCost[oneDayAgo] + 2);
}
else
{
minCost[date] = minCost[oneDayAgo];
}
}
return minCost[30];
}