結果
問題 | No.314 ケンケンパ |
ユーザー |
|
提出日時 | 2016-02-08 21:48:53 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 67 ms / 1,000 ms |
コード長 | 904 bytes |
コンパイル時間 | 1,417 ms |
コンパイル使用メモリ | 158,440 KB |
実行使用メモリ | 68,608 KB |
最終ジャッジ日時 | 2024-09-21 21:50:19 |
合計ジャッジ時間 | 2,509 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
#include <bits/stdc++.h>using namespace std;typedef long long ll;#define rep(i,n) for(i=0;i<n;++i)#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++)#define mp make_pair#define pb push_back#define fi first#define sc secondconst long mod=1e9+7;long n;//今x歩まで進んできて、ケンがy回連続しているlong dp[1000001][3];long rec(long x, long y){if(dp[x][y]>=0) return dp[x][y];long ret=0;if(x==n) ret=1;else{if(y==0){//ケンしか置けないret=rec(x+1,y+1);}else if(y==1){//両方おけるlong a=rec(x+1,y+1)%mod;long b=rec(x+1,0)%mod;ret=a+b;}else if(y==2){//パしか置けないret=rec(x+1,0);}}return dp[x][y]=ret%mod;}int main(int argc, char const *argv[]) {cin >>n;memset(dp,-1,sizeof(dp));std::cout << rec(0,0) << std::endl;return 0;}