結果

問題 No.783 門松計画
ユーザー yukarinokiyukarinoki
提出日時 2019-02-23 03:13:12
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 116 ms / 2,000 ms
コード長 1,282 bytes
コンパイル時間 1,122 ms
コンパイル使用メモリ 149,508 KB
実行使用メモリ 39,284 KB
最終ジャッジ日時 2023-09-30 18:44:02
合計ジャッジ時間 3,492 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
39,088 KB
testcase_01 AC 41 ms
39,160 KB
testcase_02 AC 42 ms
39,080 KB
testcase_03 AC 41 ms
39,284 KB
testcase_04 AC 41 ms
39,084 KB
testcase_05 AC 42 ms
39,104 KB
testcase_06 AC 39 ms
39,188 KB
testcase_07 AC 42 ms
39,076 KB
testcase_08 AC 44 ms
39,088 KB
testcase_09 AC 39 ms
39,188 KB
testcase_10 AC 54 ms
39,192 KB
testcase_11 AC 62 ms
39,088 KB
testcase_12 AC 116 ms
39,120 KB
testcase_13 AC 44 ms
39,116 KB
testcase_14 AC 45 ms
39,092 KB
testcase_15 AC 39 ms
39,164 KB
testcase_16 AC 44 ms
39,088 KB
testcase_17 AC 44 ms
39,252 KB
testcase_18 AC 44 ms
39,088 KB
testcase_19 AC 41 ms
39,096 KB
testcase_20 AC 41 ms
39,084 KB
testcase_21 AC 43 ms
39,176 KB
testcase_22 AC 41 ms
39,084 KB
testcase_23 AC 40 ms
39,180 KB
testcase_24 AC 44 ms
39,084 KB
testcase_25 AC 38 ms
39,088 KB
testcase_26 AC 44 ms
39,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int dp[55][55][55][55]; // dp[i][remind cash][h  of 2nd last][h of 1st last] = maxmum sum of height; 
int main(){
    int n,c; cin >> n >> c;
    for(int i=0;i<55;i++) for(int j=0;j<55;j++) 
      for(int k=0;k<55;k++)for(int l=0;l<55;l++) 
         dp[i][j][k][l] = -1;
    vector<int> h(n),v(n);
    for(int i=0;i<n;i++) cin >> h[i];
    for(int i=0;i<n;i++) cin >> v[i];
    for(int i=0;i<n;i++) for(int j=0;j<n;j++){
        if(h[i]!=h[j]&&c >= v[i] +v[j]) dp[2][c-v[i]-v[j]][h[i]][h[j]] =  max(dp[2][c-v[i]-v[j]][h[i]][h[j]], h[i]+h[j]);
    }
    for(int i=3; i<=55;i++){
        for(int j=1;j<51;j++) for(int k=1;k<51;k++) for(int l=1;l<51;l++){
         if(j==k || dp[i-1][l][j][k]==-1) continue;
         for(int m=0;m<n;m++){
            if(j<k && j!=h[m] && k>h[m] && l >= v[m]) dp[i][l-v[m]][k][h[m]] = max(dp[i][l-v[m]][k][h[m]], dp[i-1][l][j][k] + h[m]);     
            if(j>k && j!=h[m] && k<h[m] && l >= v[m]) dp[i][l-v[m]][k][h[m]] = max(dp[i][l-v[m]][k][h[m]], dp[i-1][l][j][k] + h[m]);     
         }
        }
    }
    int ans = 0;
    for(int i=3;i<55;i++) for(int j=0;j<55;j++) 
      for(int k=0;k<55;k++)for(int l=0;l<55;l++) 
        ans =  max(ans, dp[i][j][k][l]);
    cout << ans << endl;
    return 0;
}
0