Advertisement
Guest User

piramida

a guest
Jun 5th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1.  
  2.  
  3. #include<cstdio>
  4. #include<iostream>
  5. #include<cmath>
  6. #include<algorithm>
  7. #include<string>
  8.  
  9. #define NIL -1;
  10. using namespace std;
  11.  
  12. void przejdz(int pozycja,bool plyty[],int& sposoby,int cel)
  13. {
  14.  
  15.     int gdzie=pozycja;
  16.     for(int rzut=1;rzut<=6;++rzut)
  17.     {
  18.     gdzie=pozycja;
  19.         gdzie+=rzut;
  20.         if(gdzie==cel)
  21.             {
  22.                 ++sposoby;
  23.  
  24.                 continue;
  25.             }
  26.         else if(gdzie>cel)
  27.             return;
  28.         else if(plyty[gdzie])
  29.         przejdz(gdzie,plyty,sposoby,cel);
  30.     }
  31. }
  32.  
  33. int main()
  34. {
  35. int n,k;
  36. scanf("%d %d",&n,&k);
  37. bool plyty[n];
  38. //char wejscie[n];
  39. string wejscie;
  40. cin>>wejscie;
  41. for(int i=0;i<n;++i)
  42. {
  43.  
  44.     if(wejscie[i]=='1')
  45.         plyty[i]=true;
  46.     else
  47.         plyty[i]=false;
  48. }
  49.  
  50.  
  51. int sposoby=0;
  52. int cel=n-1;
  53. int pozycja=0;
  54. przejdz(pozycja,plyty,sposoby,cel);
  55.  
  56. printf("%d",sposoby%k);
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.     return 0;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement