結果
| 問題 | No.45 回転寿司 |
| ユーザー |
|
| 提出日時 | 2015-12-16 11:55:45 |
| 言語 | C++11 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 13 ms / 5,000 ms |
| コード長 | 503 bytes |
| 記録 | |
| コンパイル時間 | 612 ms |
| コンパイル使用メモリ | 78,292 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-06-02 01:36:13 |
| 合計ジャッジ時間 | 2,111 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 30 |
ソースコード
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
int n;
const int N = 1000;
vector<int> v(N);
int dp[1002];
//現在x番目に注目
int rec(int x){
if(x>n) return 0;
if(dp[x]>=0) return dp[x];
//x番目を食べる、食べない
return dp[x] = max( rec(x+2)+v[x], rec(x+1) );
}
int main(int argc, char const *argv[]) {
cin >>n;
for(int i=0; i<n; ++i) scanf(" %d", &v[i]);
fill(dp,dp+n+1,-1);
printf("%d\n", rec(0));
return 0;
}