6 solutions

  • 0
    @ 2024-4-16 22:37:19

    一道简单的动态规划问题,设到第i节台阶的方案数为dp[i],则dp[i] = dp[i-1] + dp[i-2];

    #include<bits/stdc++.h>
    using namespace std;
    
    long long n,dp[75];
    
    int main(){
    	cin>>n;
    	dp[0] = dp[1] = 1;
    	for(int i = 2;i<=n;i++){
    		dp[i] = dp[i-1]+dp[i-2];
    	}
    	cout<<dp[n];
    	return 0;
    }
    

    Information

    ID
    49
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    7
    Tags
    # Submissions
    565
    Accepted
    140
    Uploaded By