思路
dp(u,count)为当前再考虑下标为1-u的墙面,并且还有count免费工次的最小代价
主要是递归边界的选择:
u+1<=count return 0;
if(u==-1&&count<0)return 0x3f3f3f3f;
if(u==-1&&count==0)retrun 0;
这三个可以合并成
if(u<count) return 0;
if(u<0)return 0x3f3f3f3f;
const int N = 510;
int dp[N][2*N+10];
vector<int>times;
vector<int>costs;
int n;
int dfs(int u,int count){
if(u<count)return 0;
if(u==-1&&count<0)return 0x3f3f3f3f;
if(~dp[u][count+n])return dp[u][count+n];
int res = 0;
return dp[u][count+n] = min(dfs(u-1,count+times[u])+costs[u],dfs(u-1,count-1));
}
class Solution {
public:
int paintWalls(vector<int>& cost, vector<int>& time) {
memset(dp,-1,sizeof dp);
costs = cost;
times = time;
n = cost.size();
return dfs(n-1,0);
}
};