Created
February 19, 2016 17:34
-
-
Save kuuso/00fd8af29ca782faf20d 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(){ | |
// +1+2+..+N<N*N/2 | |
// -1-2-..-N>-N*N/2 | |
// => |Total range|<N*N | |
int NN=N*N; | |
long[] dp=new long[NN]; | |
dp[NN/2]=1; | |
for(int i=1;i<=N;i++){ | |
long[] nxt=new long[NN]; | |
for(int j=0;j<NN;j++){ | |
if(dp[j]==0)continue; | |
if(InRange(j+i,0,NN))nxt[j+i]+=dp[j]; | |
if(InRange(j-i,0,NN))nxt[j-i]+=dp[j]; | |
} | |
dp=nxt; | |
} | |
Console.WriteLine(dp[NN/2]); | |
} | |
bool InRange(int t,int l,int r){ | |
// t <- [l,r) ? | |
return (l<=t && t<r); | |
} | |
int N; | |
public Sol(){ | |
N=ri(); | |
} | |
static int ri(){return int.Parse(Console.ReadLine());} | |
} |
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
単純なDP. | |
0を作る方法が1通り、であるところからスタートして、 | |
jが作れれば j-i および j+i をそれぞれ作ることが出来るので(for i=1,2,...N) | |
Nまでそれを繰り返していく。 | |
プラスマイナス両方に振れるので、0を配列の真ん中に持ってきている。 | |
計算量は O(N^3)。 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment