class Solution {
public:
int dfs(vector cost,int x)
{
if(x==0||x==1) return 0;
return min(dfs(cost,x-1)+cost[x-1],dfs(cost,x-2)+cost[x-2]);
}
int minCostClimbingStairs(vector& cost)
{
int res=dfs(cost,cost.size());
return res;
}
};
const int N=1010;
class Solution {
public:
int mem[N];
int dfs(vector cost,int x)
{
if(mem[x]) return mem[x];
if(x==0||x==1) return 0;
return mem[x]=min(dfs(cost,x-1)+cost[x-1],dfs(cost,x-2)+cost[x-2]);
}
int minCostClimbingStairs(vector& cost)
{
int res=dfs(cost,cost.size());
return res;
}
};
const int N=1010;
class Solution {
public:
int f[N];
int minCostClimbingStairs(vector& cost)
{
int n=cost.size();
int f[N];
f[0]=f[1]=0;
for(int i=2;i<=n;i++)
{
f[i]=min(f[i-1]+cost[i-1],f[i-2]+cost[i-2]);
}
return f[n];
}
};
const int N=3010;
class Solution {
public:
int mem[N];
int dfs(vector&nums,int x)
{
if(mem[x]) return mem[x];
int res=0;
for(int i=0;i& nums) {
int n=nums.size();
int res=-0x3f3f3f3f;
for(int i=0;i
const int N=3010;
class Solution {
public:
int lengthOfLIS(vector& nums) {
int n=nums.size();
int res=-0x3f3f3f3f;
int f[N];
for(int i=0;i
const int N=10010;
class Solution {
public:
int mem[N];
int dfs(vector& coins,int x)
{
int n=coins.size();
if(mem[x]) return mem[x];
if(x==0) return 0;
if(x<0) return -1;
int res=0x3f3f3f3f;
for(int i=0;i=coins[i]) res=min(res,dfs(coins,x-coins[i])+1);
}
return mem[x]=res;
}
int coinChange(vector& coins, int amount) {
int n=coins.size();
int ans=dfs(coins,amount);
return ans==0x3f3f3f3f?-1:ans;
}
};
const int N=10010;
class Solution {
public:
int f[N];
int coinChange(vector& coins, int amount) {
int n=coins.size();
memset(f,0x3f,sizeof f);
f[0]=0;
for(int i=1;i<=amount;i++)
{
for(int j=0;j=coins[j]) f[i]=min(f[i],f[i-coins[j]]+1);
}
}
return f[amount]>1e9?-1:f[amount];
}
};
class Solution {
public:
int maxSubArray(vector& nums) {
int n=nums.size();
int maxn=-0x3f3f3f3f;
int thissum=0,maxsum=0;
for(int i=0;imaxsum) maxsum=thissum;
if(thissum<0) thissum=0;
}
if(maxsum==0) maxsum=maxn;
return maxsum;
}
};
const int N=1e5+10;
class Solution {
public:
int f[N];
int maxSubArray(vector& nums)
{
memset(f,-0x3f3f3f3f,sizeof f);
int n=nums.size();
f[0]=nums[0];
int maxn=f[0];
for(int i=1;i
const int N=100;
class Solution {
public:
int f[N]={0};
int integerBreak(int n) {
f[0]=f[1]=1;
for(int i=1;i<=n;i++)//容量
{
for(int j=0;j