結果

問題 No.783 門松計画
ユーザー face4face4
提出日時 2019-02-14 14:21:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 1,290 bytes
コンパイル時間 497 ms
コンパイル使用メモリ 65,788 KB
実行使用メモリ 4,396 KB
最終ジャッジ日時 2023-09-30 18:43:37
合計ジャッジ時間 1,643 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 6 ms
4,380 KB
testcase_11 AC 28 ms
4,396 KB
testcase_12 AC 13 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,384 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 3 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 3 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
using namespace std;

// 2つ前、1つ前のindex,所持金
int dp[51][51][101] = {};
int l[51], w[51];

bool isK(int a, int b, int c){
    return l[a] != l[b] && l[b] != l[c] && l[c] != l[a] && (l[b]-l[a])*(l[b]-l[c]) > 0;
}

int main(){
    int n, c;
    cin >> n >> c;

    for(int i = 0; i < n; i++)  cin >> l[i];
    for(int i = 0; i < n; i++)  cin >> w[i];

    // initialize
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            for(int k = 0; k < n; k++){
                int cost = w[i]+w[j]+w[k];
                if(isK(i,j,k) && cost <= c){
                    dp[j][k][cost] = max(dp[j][k][cost], l[i]+l[j]+l[k]);
                }
            }
        }
    }

    int ans = 0;
    for(int cost = 0; cost <= c; cost++){
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                if(dp[i][j][cost] == 0) continue;
                for(int k = 0; k < n; k++){
                    int ncost = cost + w[k];
                    if(isK(i,j,k) && ncost <= c){
                        dp[j][k][ncost] = max(dp[j][k][ncost], dp[i][j][cost]+l[k]);
                    }
                }
                ans = max(ans, dp[i][j][cost]);
            }
        }
    }

    cout << ans << endl;

    return 0;
}
0