結果
問題 |
No.783 門松計画
|
ユーザー |
![]() |
提出日時 | 2019-02-08 11:44:27 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 769 bytes |
コンパイル時間 | 1,712 ms |
コンパイル使用メモリ | 157,920 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-27 15:55:58 |
合計ジャッジ時間 | 2,793 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 24 WA * 3 |
ソースコード
#include <bits/stdc++.h> typedef long long ll; #define FOR(i,a,b) for(ll i=(a);i<(b);i++) #define REP(i,a) FOR(i,0,a) using namespace std; const ll MAX_L=50,MAX_C=50,MAX_N=50; ll N,C,L[MAX_N],W[MAX_N]; ll dp[MAX_L+1][MAX_L+1][MAX_C+1]; ll dfs(ll l,ll m,ll c){ if(dp[l][m][c]!=-1){ return dp[l][m][c]; } ll ret=0; REP(i,N){ if(W[i]>c)continue; if(L[i]==l || L[i]==m)continue; if(m<min(L[i],l) || m>max(L[i],l)){ ret=max(ret,dfs(m,L[i],c-W[i])+L[i]); } } return dp[l][m][c]=ret; } int main(){ cin>>N>>C; REP(i,N){ cin>>L[i]; } REP(i,N)cin>>W[i]; ll ans=0; memset(dp,-1,sizeof(dp)); REP(i,N){ REP(j,N){ if(L[i]==L[j]) continue; if(W[i]+W[j]>C) continue; ans=max(ans,L[i]+L[j]+dfs(L[i],L[j],C-W[i]-W[j])); } } cout<<ans<<endl; }