結果

問題 No.783 門松計画
ユーザー yukarinokiyukarinoki
提出日時 2019-02-23 03:09:13
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,282 bytes
コンパイル時間 2,573 ms
コンパイル使用メモリ 147,184 KB
実行使用メモリ 39,408 KB
最終ジャッジ日時 2023-08-18 06:23:29
合計ジャッジ時間 4,348 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
39,272 KB
testcase_01 AC 46 ms
39,144 KB
testcase_02 AC 45 ms
39,116 KB
testcase_03 AC 46 ms
39,176 KB
testcase_04 AC 46 ms
39,148 KB
testcase_05 AC 46 ms
39,096 KB
testcase_06 AC 46 ms
39,144 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 47 ms
39,092 KB
testcase_10 AC 57 ms
39,092 KB
testcase_11 AC 71 ms
39,076 KB
testcase_12 AC 120 ms
39,148 KB
testcase_13 AC 50 ms
39,140 KB
testcase_14 AC 50 ms
39,068 KB
testcase_15 AC 46 ms
39,100 KB
testcase_16 AC 45 ms
39,144 KB
testcase_17 AC 46 ms
39,240 KB
testcase_18 AC 46 ms
39,172 KB
testcase_19 AC 46 ms
39,148 KB
testcase_20 AC 46 ms
39,144 KB
testcase_21 AC 47 ms
39,228 KB
testcase_22 WA -
testcase_23 AC 45 ms
39,164 KB
testcase_24 AC 47 ms
39,112 KB
testcase_25 AC 46 ms
39,096 KB
testcase_26 AC 46 ms
39,336 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=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++) 
        ans =  max(ans, dp[i][j][k][l]);
    cout << ans << endl;
    return 0;
}
0