Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. /*
  2. M == 1
  3. 10 -> START
  4.  
  5. 10 -> 10, 01
  6. 01 -> 10, 01
  7.  
  8. GOAL -> 01
  9.  
  10. M == 2
  11. 100 -> START
  12.  
  13. 001 -> 001, 010, 100, 111L
  14. 010 -> 001, 010, 100
  15. 100 -> 001, 010, 100, 111R
  16. 111L-> 100, 111L
  17. 111R-> 001, 111R
  18.  
  19. GOAL -> 001
  20. */
  21.  
  22. #include <iostream>
  23.  
  24. using namespace std;
  25. const long MOD = 1000000;
  26. enum SET {
  27. oox, oxo, xoo, xxxL, xxxR
  28. };
  29.  
  30. bool canTravel[5][5] = {
  31. {true, true, true, true, false},
  32. {true, true, true, false, false},
  33. {true, true, true, false, true},
  34. {false, false, true, true, false},
  35. {true, false, false, false, true}
  36. };
  37.  
  38. long solve1(int N);
  39. long solve2(int N);
  40.  
  41. int main() {
  42. int N,M;
  43. cin >> N >> M;
  44. long ans;
  45. if (M==1) {
  46. ans = solve1(N);
  47. } else {
  48. ans = solve2(N);
  49. }
  50. cout << ans << endl;
  51. return 0;
  52. }
  53.  
  54. long solve1(int N) {
  55. long ans = 1;
  56. for (int i=0; i<N; ++i) {
  57. ans *= 2;
  58. ans %= MOD;
  59. }
  60. return ans;
  61. }
  62. long solve2(int N) {
  63. long ans = 0;
  64. long dp[101][5] = {{0}};
  65. dp[0][(SET)xoo] = 1;
  66. for (int i=1; i<=N; ++i) {
  67. for (int jfrom=0; jfrom<5; ++jfrom) {
  68. for (int j2=0; j2<5; ++j2) {
  69. if (canTravel[jfrom][j2]) {
  70. dp[i][j2] += dp[i-1][jfrom];
  71. dp[i][j2] %= MOD;
  72. }
  73. }
  74. }
  75. }
  76.  
  77. for (int jfrom=0; jfrom<5; ++jfrom) {
  78. SET j2 = oox;
  79. if (canTravel[jfrom][j2]) {
  80. ans += dp[N][jfrom];
  81. ans %= MOD;
  82. }
  83. }
  84. return ans;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement