We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
링크
dp[1] = stairs[1]; dp[2] = stairs[1] + stairs[2];
dp[i] = stairs[i] + max(dp[i - 3] + stairs[i - 1], dp[i - 2]);
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; vector<int> stairs; vector<long long> dp; void solution() { int N; cin >> N; stairs.resize(N + 1); dp.resize(N + 1); for (int i = 1; i <= N; i++) { cin >> stairs[i]; } dp[1] = stairs[1]; dp[2] = stairs[1] + stairs[2]; for (int i = 3; i <= N; i++) { dp[i] = stairs[i] + max(dp[i - 3] + stairs[i - 1], dp[i - 2]); } cout << dp[N] << "\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); solution(); return 0; }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
2579. 계단 오르기
링크
설계
점화식
dp[1] = stairs[1];
dp[2] = stairs[1] + stairs[2];
dp[i] = stairs[i] + max(dp[i - 3] + stairs[i - 1], dp[i - 2]);
정리
고생한 점
코드
The text was updated successfully, but these errors were encountered: