fork download
  1. n,m=gets.split(" ").map{|e| e.to_i}
  2. xs=gets.split(" ").map{|e| e.to_i}
  3. rr=[]
  4. (n+4).times{|i|
  5. rr[i]=[]
  6. (n+4).times{|j|
  7. rr[i][j]=0
  8. }
  9. }
  10. rr[0][0]=1
  11. ans=0
  12. mod=10**9+7
  13. 0.upto(n){|i|
  14. 0.upto(n){|j|
  15. p1=i+j
  16. break if n<=p1
  17. if i==0 || p1==0 || xs[i-1]<xs[p1] then
  18. rr[p1+1][j]=(rr[p1+1][j]+rr[i][j])%mod
  19. end
  20. if j==0 || p1==0 || xs[j-1]<xs[p1] then
  21. rr[i][p1+1]=(rr[i][p1+1]+rr[i][j])%mod
  22. end
  23. }
  24. }
  25. rr.each{|e| p e }
  26.  
  27. puts ans
Success #stdin #stdout 0.01s 7936KB
stdin
6 6
1 3 4 2 6 5
stdout
[1, 1, 1, 1, 0, 0, 0, 0, 0, 0]
[1, 0, 1, 0, 0, 0, 0, 0, 0, 0]
[1, 1, 0, 1, 1, 0, 1, 0, 0, 0]
[1, 0, 1, 0, 1, 0, 1, 0, 0, 0]
[0, 0, 1, 1, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 1, 1, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
0