Advertisement
Josif_tepe

Untitled

Oct 27th, 2021
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4. int n;
  5. long long dp[115];
  6. int niza[115];
  7. long long fc(int i){
  8.     if(i==n){
  9.         return 1;
  10.     }
  11.     if(dp[i]!=-1){
  12.         return dp[i];
  13.     }
  14.     long long result=0;
  15.     int zbir=0;
  16.  
  17.     for(int j=i;  j<n; j++){
  18.         zbir+=niza[j];
  19.         if(zbir==1){
  20.             result+=fc(j+1);
  21.  
  22.         }
  23.     }
  24.     return dp[i] = result;
  25. }
  26.  
  27.  
  28.  
  29.  
  30.  
  31. int main()
  32. {
  33.  
  34.     cin>>n;
  35.  
  36.     for(int i=0; i<n; i++){
  37.      cin>>niza[i];
  38.     }
  39.     for(int i=0; i<n; i++){
  40.         dp[i]=-1;
  41.     }
  42.     cout<<fc(0) << endl;
  43. return 0;
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement