0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

発電計画問題

Last updated at Posted at 2022-03-15

問題

dp[t]
時刻 t までの総利得の最大値

区間[ i~j ]の利得はg[i][j-1]である


// 入力
int T1;
int g[110][110];

// DP テーブル
int dp[110];

int main() {
    cin >> T1; //時刻
    for (int i = 0; i < T1; ++i) for (int j = 0; j < T1; ++j) cin >> g[i][j]; //利得

    // DP テーブル初期化
    memset(dp, 0, sizeof(dp));

    // DP ループ
    for (int t = 1; t <= T1 + 1; ++t) { //時間
        for (int i = 0; i < t; ++i) { //始まり
            for (int j = i + 1; j < t; ++j) { //終わり
                dp[t] = max(dp[t], dp[i] + g[i][j - 1]); //すべての区間を試す
            }
        }
    }
    cout << dp[T1 + 1] << endl; //g[i][j - 1]より
}
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?