This commit is contained in:
Mrhongxing committed 2026-10-19 15:43:40 +08:00
1 parent c5025637ee
commit ac5b43af95
4 files changed
+128

No files matched your search

+28
View File
@@ -0,0 +1,28 @@
package com.hong.www;
public class A3693 {
public int climbStairs(int n, int[] costs) {
if(n==0){
return 0;
}else if(n==1){
return costs[0]+1;
}else if(n==2){
return Math.min(4+costs[1], costs[1]+1+1+costs[0]);
}
int[] dp=new int[n+1];
dp[0]=0;
dp[1]=costs[0]+1;
dp[2]=Math.min(dp[0]+4+costs[1], dp[1]+costs[1]+1);
for(int i=3;i<=n;i++){
dp[i]=Math.min(dp[i-2]+4+costs[i-1], Math.min(dp[i-1]+costs[i-1]+1, dp[i-3]+9+costs[i-1]));
}
return dp[n];
}
public static void main(String[] args) {
A3693 a3693 = new A3693();
int n = 2;
int[] costs = {4, 6};
int result = a3693.climbStairs(n, costs);
System.out.println("The minimum cost to climb " + n + " stairs is: " + result);
}
}