Created
March 5, 2015 14:03
-
-
Save kuuso/a9455051742b34b3d581 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
class TEST{ | |
static void Main(){ | |
Sol mySol =new Sol(); | |
mySol.Solve(); | |
} | |
} | |
class Sol{ | |
public void Solve(){ | |
//dp[n][m][flg]:n個並べた時に、一番右に連続した黒石がm個ある組み合わせ。 | |
// flgは M個を達成したかどうか(0/1) | |
long[][][] dp=new long[N+1][][]; | |
for(int i=0;i<=N;i++){ | |
dp[i]=new long[M+1][]; | |
for(int j=0;j<=M;j++){ | |
dp[i][j]=new long[2]; | |
} | |
} | |
checked{ | |
dp[0][0][0]=1; | |
for(int i=0;i<N;i++){ | |
for(int j=0;j<=M;j++){ | |
//i+1番目に白を置く | |
dp[i+1][0][0]+=dp[i][j][0]; | |
dp[i+1][0][1]+=dp[i][j][1]; | |
//i+1番目に黒を置く | |
if(j+1<M){ | |
dp[i+1][j+1][0]+=dp[i][j][0]; | |
dp[i+1][j+1][1]+=dp[i][j][1]; | |
} | |
if(j+1==M){ | |
dp[i+1][j+1][1]+=dp[i][j][0]; | |
dp[i+1][j+1][1]+=dp[i][j][1]; | |
} | |
} | |
} | |
} | |
long Ans=0; | |
for(int i=0;i<=M;i++)Ans+=dp[N][i][1]; | |
Console.WriteLine(Ans); | |
} | |
int N,M; | |
public Sol(){ | |
N=30; | |
M=5; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment