LoginSignup
1
0

More than 3 years have passed since last update.

AtCoder Typical DP Contestの「A - コンテスト」を絵で理解してみたい(PHP)

Last updated at Posted at 2020-12-06

AtCoderのこちらの問題に挑戦してみました。
https://atcoder.jp/contests/tdpc/tasks/tdpc_contest

入力例
3
2 3 5
PHP
<?php
    fscanf(STDIN, "%d", $d);
    $ps = explode(" ", trim(fgets(STDIN)));

    $ans = array([0 => TRUE]);

    foreach ($ps as $p) {
        foreach ($ans as $k => $v) {
            $ans[$k + $p] = TRUE;
        }
    }
    echo count($ans) . "\n";

foreachの中でforeachを回して、中のforeachの配列は処理中に中身が増えていきます。よりイメージしやすいように絵に描いてみました。

スクリーンショット 2020-12-06 14.53.05.png

こちらの記事は自分用のメモですが、適宜追記していきます。
コメントあれば、ぜひよろしくお願い申し上げます。

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