No.37 遊園地のアトラクション

No.37 遊園地のアトラクション - yukicoder

  • アトラクション i を訪れるたびに満足度が半減するのをどう表現するか。
  • v[i]/2^k, C[i] のアトラクションがあると考える。
class AmusementParkAttraction {
public:
    void solve(void) {
            int T,N;
            cin>>T>>N;
            vector<int> C(N);
            REP(i,N)
                cin>>C[i];
            vector<int> V(N);
            REP(i,N)
                cin>>V[i];
            // DP でやれそうな問題。
            // ポイントはアトラクション i を訪れるたびに満足度が半減するのをどう表現するか。
            // 満足度を半減させていったものを新しいアトラクションとみなす。
            vector<pair<int,int>> V2;
            REP(i,N)
            {
                int v = V[i];
                while (v > 0)
                {
                    V2.emplace_back(C[i],v);
                    v /= 2;
                }
            }
            // V2.size() <= 15*log2(500) <= 135
            // 後は通常どおり DP
            // 満足度が最大になる組み合わせには V[i]/2 が含まれるなら当然 V[i] が含まれる形になる。
            N = V2.size();
            vector<vector<ll>> dp(N+1, vector<ll>(T+1,0));
            REP(i,N)
            REP(t,T+1)
            {
                int c,v;
                tie(c,v) = V2[i];
                if (c <= t)
                    dp[i+1][t-c] = max(dp[i+1][t-c], dp[i][t]+v);
                dp[i+1][t] = max(dp[i+1][t], dp[i][t]);
            }
            ll res = 0;
            REP(t,T+1)
                res = max(res,dp[N][t]);
            cout<<res<<endl;
    }
};