一道简单的动态规划问题,设到第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; }
By signing up a 追梦算法网 universal account, you can submit code and join discussions in all online judging services provided by us.
Using your 追梦算法网 universal account