LoginSignup
1
0

More than 5 years have passed since last update.

SRM 428 Round 1 - Division II, Level One

Posted at

topcoderの問題をやってみようかなシリーズ。
動的計画法で絞って簡単な方から少しずつやり始めている。
https://community.topcoder.com/stat?c=problem_statement&pm=10240

この問題は、式通りに加算していくだけ。

public class ShorterSuperSum {

public int calculate(int k, int n) {
    int[][] dp = new int[k + 1][n + 1];
    for (int i = 0; i <= n; i++) {
        dp[0][i] = i;
    }

    for (int i = 1; i <= k; i++) {
        for (int j = 1; j <=n; j++ ) {
            for (int p = 1; p <= j; p++) {
                dp[i][j] += dp[i - 1][p];
            }
        }
    }

    return dp[k][n];
}

}

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0