Advertisement
gamerslouis

d702

Sep 25th, 2016
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. //d702
  2.  
  3. #include <iostream>
  4. #include <stdlib.h>
  5. using namespace std;
  6. int main()
  7. {
  8.     int  n;
  9.     while (cin >> n)
  10.     {
  11.         unsigned long  count[1000][3]; // 0 = x,1 = 1,or 2's 2 , 2 = 1
  12.         count[n - 1][0] = 0;
  13.         count[n - 1][1] = 1;
  14.         count[n - 1][2] = 0;
  15.         if (n > 1)
  16.         {
  17.             count[n - 2][0] = 1;
  18.             count[n - 2][1] = 0;
  19.             count[n - 2][2] = 1;
  20.         }
  21.         for (unsigned long i = n - 2; i > 0; i--)
  22.         {
  23.             count[i - 1][0] = count[i][1] + count[i][2];
  24.             count[i - 1][1] = count[i][0];
  25.             count[i - 1][2] = count[i][1];
  26.         }
  27.  
  28.         cout << count[0][1] + count[0][2] << endl;
  29.  
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement