숨숨숨 2021. 2. 22. 01:36

👀 문제 설명

문제

로그인해야 문제를 볼 수 있다

✍🏻풀이

DP를 사용해 각 숫자까지의 더한 값 dp배열에 저장해두고, 출력한다.

 

코드

#include <stdio.h>
#include <iostream>

using namespace std;

int dp[10001];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(NULL); cout.tie(NULL);
    
    int n;
    cin >> n;
    
    dp[1] = 1;
    for (int i = 2; i <= n; i++) {
        dp[i] = dp[i - 1] + i;
    }
    
    cout << dp[n] << "\n";
    
    return 0;
}